Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the connection with Ip network segment by using Docker

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to use Docker to connect with IP network segment? In response to this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more small partners who want to solve this problem find a simpler and easier way.

1. Install Docker(Linux Server)

install Docker

yum install docker

2. Configure a standalone IP for docker containers using pipework

Install pipework This tool allows you to change the IP of a container with a single command, or more precisely add a new network card to the container IP.

wget https://github.com/jpetazzo/pipework/archive/master.zipunzip master.zip cp pipework-master/pipework /usr/local/bin/chmod +x /usr/local/bin/pipework

3. Edit IP configuration file, eh0

Edit the default ip configuration file, eth0 or ens33(different operating systems, different names, for example, the name of the machine I operate is ifcfg-ens33)

vim /etc/sysconfig/network-scripts/ifcfg-ens33

Enter i to enter edit mode and copy the following to the file

TYPE= Ethernet PROXY_METHOD=noneBROWSER_ONLY=noBOOTPROTO= dhcpDEROUTE =yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF= yesIPV6 6_DEFROUTE =yesIPV6_FAILURE_FATAL=noIPV6_ADDR_GEN_MODE=stable-privacyNAME=ens33UUID=36b40bc6-6775-4e02- 88 161-e245d0e3892fDEVICE=ens33#The following is the bridge part setting ONBOOT=yesBRIDGE=br0PEERDNS=yesPEERROUTES=yesIPV6_PEERDNS = yesIPV6_PEERROUTES=yes

4. Create a custom bridgebr 0

vim ifcfg-br0

and copy the configuration to the configuration file.

DEVICE=br0 BOOTPROTO=static NM_CINTROLLER=no ONBOOT=yes TYPE=Bridge IPADDR=192.168.186.128 NETMASK=255.255.255.0

Restart virtual machine network services

systemctl restart network

5. Modify docker configuration file to specify bridge

/etc/sysconfig/

vim /etc/sysconfig/docker

as modified by

OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'

Amend to read:

OPTIONS='--selinux-enabled -b=br0'

After modification:

# /etc/sysconfig/docker# Modify these options if you want to change the way the docker daemon runs#OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'OPTIONS='--selinux-enabled -b=br0'if [ -z "${DOCKER_CERT_PATH}" ]; then DOCKER_CERT_PATH=/etc/dockerfi# Do not add registries in this file anymore. Use /etc/containers/registries.conf# instead. For more information reference the registries.conf(5) man page.# Location used for temporary files, such as those created by# docker load and build operations. Default is /var/lib/docker/tmp# Can be overriden by setting the following environment variable.# DOCKER_TMPDIR=/var/tmp# Controls the /etc/cron.daily/docker-logrotate cron job status.# To disable, uncomment the line below.# LOGROTATE=false# docker-latest daemon can be used by starting the docker-latest unitfile.# To use docker-latest client, uncomment below lines#DOCKERBINARY=/usr/bin/docker-latest#DOCKERDBINARY=/usr/bin/dockerd-latest#DOCKER_CONTAINERD_BINARY=/usr/bin/docker-containerd-latest#DOCKER_CONTAINERD_SHIM_BINARY=/usr/bin/docker-containerd-shim-latestother_args='-b br0'

5. Restart Docker service

systemctl restart docker

6. Create Docker container instance

docker run -itd --name test1 --net=none centos /bin/bash

--net=none represents that the network cards of the container are empty, and need to be customized through pipework.

7. Specify the network card

pipework br0 test1 192.168.186.111/24@192.168.186.128

8. Enter the container and try to Ping the host and the IP of the same network segment.

#Enter container docker attach test1 #ping host ping 192.168.186.22

8.1 Modify IP of the same network segment host

Modify the host IP so that the network segment is consistent with the IP segment of the host A bridge. After setting, hosts A and B can ping each other.

# ping the same IP segment Ipping 192.168.186.33 About how to use Docker to achieve the same IP segment connectivity problem to share here, I hope the above content can be of some help to everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report