1. 程式人生 > >Docker:跨主機容器間通信之overlay [十五]

Docker:跨主機容器間通信之overlay [十五]

boot mes ports usr unable network oot tcp 解決方案

一、配置overlay類型網絡準備工作

1、在luoahong3主機上

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

[root@luoahong3 ~]# 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
[root@luoahong3 ~]# 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 [十五]