Cross-host communication

JOIN container: container (shared network protocol stack)

Between the container and the container.

[root@localhost ~]# docker pull busybox

[root@localhost ~]# docker run -itd --name web5 busybox:latest

NIC designated web5:

[root@localhost ~]# docker run -itd --name web6 --network container:web5 busybox:latest

Web6:

[root@localhost ~]# docker exec -it web6 /bin/sh

/ # echo 123456 > /tmp/index.html

/ # httpd -h /tmp/

Web5:

[root@localhost ~]# docker exec -it web5 /bin/sh

/ # wget -O - -q 127.0.0.1

At this time you will find the same ip address two containers.

PS: This method uses scenarios: Due to the particularity of such a network, usually run in the same service, and qualified service needs to do monitoring, and log collection, or network monitoring, they can select this network.

docker across the host network solutions

Overlay solutions (covering solutions)

lab environment:

Docker01:1.10

Docker02:1.20

Docker03:1.30

Not to consider a firewall and selinux security issues.

The three Dockerhost firewall and selinux all closed, and are changing the host name

[root@localhost ~]# hostnamectl set-hostname docker01

[root@localhost ~]# su -

[root@docker01 ~]# systemctl stop firewalld

[root@docker01 ~]# systemctl disable firewalld

[root@docker01 ~]# setenforce 0

Docker01:

[root @ docker01 ~] # rz
import image packages:

Cross-host communication
[root @ docker01 ~] # Docker -i myprogrium the Load-consul.tar
Cross-host communication
-h: hostname, hostname -server -bootstrap: Cluster

Services start consul: consul: the way distributed, databases, data center, cluster storage stuff

[root@docker01 ~]#docker run -d -p 8500:8500 -h consul --name consul --restart always progrium/consul -server -bootstrap

Error restart the service:

[root@docker01 ~]# systemctl restart docker

PS: After container production, we can access the service through a browser consul, consul verify service is normal. Access dockerHost plus port mapping.

access:

http://192.168.1.10:8500/
Cross-host communication
modify Docker02 and Docker03 profile

Docker02:

[root@docker02 ~]# vim /usr/lib/systemd/system/docker.service

Line 13:

ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2376 --cluster-store=consul://192.168.1.10:8500 --cluster-advertise=ens33:2376

[root@docker03 ~]# systemctl daemon-reload

[root@docker03 ~]# systemctl restart docker

Docker03 Ibid.

PS: return to the browser service interface consul did not find KEY / VALUE -----> DOCKER ------> NODES will see just joined docker02 of information.

Create a custom network on docker02: global (Global)

Docker02 created on the network, we can see that it is defined by the SCOPE global (global), meaning that this service is added to the consul docker service, you can see our custom network.

Similarly, if the container is used to create this network, there will be two cards.

This card is the default network 10.0.0.0 network segment, if you want to docker01 can also see this network, then they only need to add the appropriate content in docker01 profile.

Similarly, because the custom network, consistent set of characteristics defined network, can communicate with each other directly via name docker container, of course, also be custom network when specifying its network segment, then this network is

docker network create -d overlay ov_net1
Cross-host communication
view card on docker03:
Cross-host communication
modify the configuration files on docker01, restart docker View:

[root@docker01 ~]# vim /usr/lib/systemd/system/docker.service

Line 13:

ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2376 --cluster-store=consul://192.168.1.10:8500 --cluster-advertise=ens33:2376

[root@docker01 ~]# systemctl daemon-reload

[root@docker01 ~]# systemctl restart docker

[root@docker01 ~]# docker network ls
Cross-host communication

Docker01:

[root@docker01 ~]# docker run -itd --name t1 --network ov_net1 busybox

[root@docker01 ~]# docker exec -it t1 /bin/sh

/ # ip a

Docker02:

[root@docker02 ~]# docker run -itd --name t2 --network ov_net1 busybox

[root@docker02 ~]# docker exec -it t1 /bin/sh

/ # ip a

Docker03:

[root@docker03 ~]# docker run -itd --name t3 --network ov_net1 busybox

[root@docker03 ~]# docker exec -it t1 /bin/sh

/ # ip a

Cross-host communication

Guess you like

Origin blog.51cto.com/13997536/2460487