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 between Docker and Ip Network Segment

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how to realize the connection between Docker and Ip network segment". In the daily operation, I believe that many people have doubts about how to realize the connection between Docker and Ip network segment. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to achieve interconnection between Docker and Ip network segment". Next, please follow the editor to study!

For example

Host an and host b are connected to each other, and multiple containers are created on host a to form a cluster, but I hope that host a can also be accessed through host b. Of course, you may also say that port mapping is very convenient, if I need more ports, or if I need to add some ports temporarily, it may be troublesome to set up. So if we put the ip of the container in host an and the ip of host on the same network, we can interconnect and communicate directly.

1. Install docker (linux server)

Install docker

Yum install docker

2. Use pipework to configure an independent ip for the docker container

To install pipework, you can use a single command to change the container's ip and, more accurately, 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 the configuration file of ip, eh0

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

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

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

Type=ethernetproxy_method=nonebrowser_only=nobootproto=dhcpdefroute=yesipv4_failure_fatal=noipv6init=yesipv6_autoconf=yesipv6_defroute=yesipv6_failure_fatal=noipv6_addr_gen_mode=stable-privacyname=ens33uuid=36b40bc6-6775-4e02-8161-e245d0e3892fdevice=ens33# below sets the onboot=yesbridge=br0peerdns=yespeerroutes=yesipv6_peerdns=yesipv6_peerroutes=yes for the bridging part

4. Create a custom bridge br0

Vim ifcfg-br0

And copy the configuration content 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 service

Systemctl restart network

5. Modify the docker configuration file to specify the bridge

Modify the configuration file / etc/sysconfig/ of docker

Vim / etc/sysconfig/docker

The modifications are as follows

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

Modified to:

Options='--selinux-enabled-baked 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 the docker service

Systemctl restart docker

6. Create a docker container instance

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

-- net=none represents that the NICs of the container are empty and need to be customized and specified through pipework.

7. Specify the network card

Pipework br0 test1 192.168.186.111Universe 192.168.186.128

8. Enter the container and try whether the ping host and the ip of the same IP address range can communicate with ping.

# enter the container docker attach test1# ping host ping 192.168.186.22

8.1 modify the ip of the host on the same network segment

Modify the host ip to keep the network segment consistent with the host a bridge ip segment. After setting up, host a _ ping b can communicate with each other

# ping with network segment ipping 192.168.186.33 at this point, the study on "how to connect Docker with Ip network segment" is over. I hope to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Development

Wechat

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

12
Report