在我的场景中,我使用“consul”作为键值存储后端,另外还有两个安装了docker的VM。我在这两个VM上运行docker守护程序的命令是:
sudo docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock \
--cluster-store consul://{CONSUL_IP}:8500 --cluster-advertise eth0:2376
运行领事的命令也是:
sudo docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
在此之后,我尝试使用以下方法创建网络:
sudo docker network create -d overlay --subnet=192.168.3.0/24 my-overlay
在每个VM中,我运行一个busybox容器:
sudo docker run -itd --name containerX --net my-overlay busybox
其中X代表其中一个,B代表另一个。
这是来自第一个VM的“docker info”:
$ sudo docker info
Containers: 4
Running: 2
Paused: 0
Stopped: 2
Images: 3
Server Version: 1.12.3
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 17
Dirperm1 Supported: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: overlay bridge host null
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: apparmor
Kernel Version: 3.13.0-76-generic
Operating System: Ubuntu 14.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.955 GiB
Name: cs-webserving-4
ID: ESSZ:WBCV:W6NU:ODJ6:3ZIW:QHMH:TEXP:M66M:NYF5:MNWB:H4M7:Z3L6
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Cluster Store: consul://10.254.1.92:8500
Cluster Advertise: 10.254.1.123:2376
Insecure Registries:
127.0.0.0/8
这是另一个VM:
$ sudo docker info
Containers: 4
Running: 2
Paused: 0
Stopped: 2
Images: 3
Server Version: 1.12.3
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 17
Dirperm1 Supported: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: overlay host bridge null
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: apparmor
Kernel Version: 3.13.0-76-generic
Operating System: Ubuntu 14.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.955 GiB
Name: cs-webserving-3
ID: BTAL:L3LE:BHSX:DQRD:HTC4:KXJE:T772:47TU:4KJZ:NIY4:7WTY:Q6TO
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Cluster Store: consul://10.254.1.92:8500
Cluster Advertise: 10.254.1.122:2376
Insecure Registries:
127.0.0.0/8
问题 当我尝试从containerA ping容器B时,我得不到答案:
sudo docker exec containerB ping -w 5 192.168.3.5
PING 192.168.3.5 (192.168.3.5): 56 data bytes
--- 192.168.3.5 ping statistics ---
5 packets transmitted, 0 packets received, 100% packet loss
其中192.168.3.5是覆盖网络中containerA的IP。 **注意:**我也尝试使用名称“containerA”而不是IP,但它也没有用。
我的方案有什么问题?任何提示或解决方案都将不胜感激。
答案 0 :(得分:1)
尝试链接容器。
前:
$ docker run -ti --name containerA --link containerB:containerB_alias ubuntu bash
你可以ping:[root@cad0fef8c778]$ ping containerB_alias