Docker:跨主机容器间通信之overlay [十五]

Posted luoahong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker:跨主机容器间通信之overlay [十五]相关的知识,希望对你有一定的参考价值。

一、配置overlay类型网络准备工作

1、在luoahong3主机上

docker run -d -p 8500:8500 -h consul --name consul progrium/consul -server -bootstrap

[[email protected] ~]# docker run -d -p 8500:8500 -h consul --name consul progrium/consul -server -bootstrap
Unable to find image ‘progrium/consul:latest‘ locally

latest: Pulling from progrium/consul
c862d82a67a2: Pull complete 
0e7f3c08384e: Pull complete 
0e221e32327a: Pull complete 
09a952464e47: Pull complete 
60a1b927414d: Pull complete 
4c9f46b5ccce: Pull complete 
417d86672aa4: Pull complete 
b0d47ad24447: Pull complete 
fd5300bd53f0: Pull complete 
a3ed95caeb02: Pull complete 
d023b445076e: Pull complete 
ba8851f89e33: Pull complete 
5d1cefca2a28: Pull complete 
Digest: sha256:8cc8023462905929df9a79ff67ee435a36848ce7a10f18d6d0faba9306b97274
Status: Downloaded newer image for progrium/consul:latest
485d84362a1d7b3e3c0df34451cb8d228abd1f15487a9ec94dc6c6c9f93d60b5
[[email protected] ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                                                                            NAMES
485d84362a1d        progrium/consul     "/bin/start -server …"   About a minute ago   Up About a minute   53/tcp, 53/udp, 8300-8302/tcp, 8400/tcp, 8301-8302/udp, 0.0.0.0:8500->8500/tcp   consul

2、在luoahong主机上

vim  /etc/docker/daemon.json
{
  "hosts":["tcp://0.0.0.0:2376","unix:///var/run/docker.sock"],
  "cluster-store": "consul://192.168.231.138:8500",
  "cluster-advertise": "192.168.231.136:2376",
  "insecure-registries": ["192.168.231.136:5000"]
}

 systemctl restart docker

 可能会报错解决方案如下

vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd 
systemctl daemon-reload
systemctl restart docker

3、在luoahong1主机上  

vim  /etc/docker/daemon.json
{
  "hosts":["tcp://0.0.0.0:2376","unix:///var/run/docker.sock"],
  "cluster-store": "consul://192.168.231.138:8500",
  "cluster-advertise": "192.168.231.137:2376",
  "insecure-registries": ["192.168.231.136:5000"]
}

 systemctl restart docker

 可能会报错解决方案如下

vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd 
systemctl daemon-reload
systemctl restart docker

4、测试截图

技术分享图片

 

 

一、创建网络启动容器

1、创建overlay网络

docker network create -d overlay ol3

2、启动容器测试

docker run -it --network ol3 --name oldboy02 busybox:latest /bin/sh

3、测试截图

技术分享图片

技术分享图片

三、overlay类型网络原理图

技术分享图片

 

以上是关于Docker:跨主机容器间通信之overlay [十五]的主要内容,如果未能解决你的问题,请参考以下文章

【swarm】Docker跨主机网络:overlay

Docker 跨主机网络(十六)

docker容器跨主机网络overlay

overlay 如何实现跨主机通信?- 每天5分钟玩转 Docker 容器技术(52)

overlay 如何实现跨主机通信?- 每天5分钟玩转 Docker 容器技术(52)

Docker网络之部署跨主机网络overlay