Docker overlay网络互通
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker overlay网络互通相关的知识,希望对你有一定的参考价值。
1 yum install docker-ce -y yum install python-pip -y pip install docker-compose systemctl enable docker.service systemctl start docker.service docker pull progrium/consul 环境: 192.168.56.11 192.168.56.12 192.168.56.13 目的实现192.168.56.11 自建网络互通 192.168.56.13 docker run -d -p 8500:8500 --name consul progrium/consul -server -bootstrap 192.168.56.11 /usr/lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd -H tcp://192.168.56.11 -H unix://var/run/docker.sock [[email protected] ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["http://224ac393.m.daocloud.io"], "cluster-store": "consul://192.168.56.13:8500", "cluster-advertise": "192.168.56.11:2375" } [[email protected] ~]# systemctl daemon-reload systemctl restart docker 192.168.56.12 /usr/lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd -H tcp://192.168.56.12 -H unix://var/run/docker.sock [[email protected] ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["http://224ac393.m.daocloud.io"], "cluster-store": "consul://192.168.56.13:8500", "cluster-advertise": "192.168.56.12:2375" } [[email protected] ~]# systemctl daemon-reload systemctl restart docker 浏览器浏览 测试 192.168.56.11 上面 docker network create -d overlay --subnet 192.168.1.0/24 ov_net1 #192.168.56.12 上面默认就有了 不用创建了 [[email protected] ~]# docker network ls NETWORK ID NAME DRIVER SCOPE 587ebbdc8cf6 bridge bridge local 42863825595a docker_gwbridge bridge local df6484f00517 host host local adf74519830e none null local e8d259aa8fe3 ov_net1 overlay global [[email protected] ~]# [[email protected] ~]# docker network ls NETWORK ID NAME DRIVER SCOPE 624c4d1628bd bridge bridge local 4f7d45ab8d94 docker_gwbridge bridge local df6484f00517 host host local adf74519830e none null local e8d259aa8fe3 ov_net1 overlay global [[email protected] ~]# 192.168.56.11测试 docker run -it --rm --net=ov_net1 busybox 192.168.56.12测试 docker run -it --rm --net=ov_net1 busybox 查看两个容器的IP地址互相ping下 可以ping通 docker run -it --rm --net=ov_net1 --ip=192.168.1.10 busybox #指定IP地址
以上是关于Docker overlay网络互通的主要内容,如果未能解决你的问题,请参考以下文章