[英]Problems getting docker containers to see (ping) each other by name
I have three docker containers, 我有三个码头工人,
Currently, the JC cannot see the EC by "name". 目前,JC无法通过“名称”看到EC。 And when I say "see" I mean if I do a ping on the JC to EC, I get a
ping: unknown host
. 当我说“看”时,我的意思是如果我在JC上对EC进行
ping: unknown host
,我会得到一个ping: unknown host
。 Interestingly, if I do a ping on the TC to EC, I do get a response. 有趣的是,如果我对TC的EC进行ping操作,我会得到回复。
Here is how I start the containers. 这是我如何启动容器。
docker run -dit --name JC myapp-image
docker run -d --name EC elasticsearch:1.5.2 elasticsearch -Des.cluster.name=es
docker run --rm --name TC -it busybox:latest
Then, to ping EC from JC, I issue the following commands. 然后,为了从JC ping EC,我发出以下命令。
docker exec JC ping -c 2 EC
I get a ping: unknown host
我得到一个
ping: unknown host
With the TC, since I am already at the shell, I can just do a ping -c 2 EC
and I get 2 replies. 有了TC,因为我已经在shell,我可以做一个
ping -c 2 EC
,我得到2个回复。
I thought maybe this had something to do with my Java application, but I doubt it because I modified my Dockerfile
to just stand up the container. 我想也许这与我的Java应用程序有关,但我怀疑它是因为我修改了我的
Dockerfile
只是站起来容器。 The Dockerfile
looks like the following. Dockerfile
如下所示。
FROM java:8
VOLUME /tmp
Note that you can create the above docker image by docker build -no-cache -t myapp-image .
请注意,您可以通过
docker build -no-cache -t myapp-image .
创建上述docker docker build -no-cache -t myapp-image .
. 。
Also note that I have Docker Weave Net installed, and this does not seem to help getting the JC to see the EC by name. 另请注意,我安装了Docker Weave Net,这似乎无助于让JC通过名称查看EC。 On the other hand, I tried to find the IP address of each container as follows.
另一方面,我试图找到每个容器的IP地址如下。
docker inspect -f '{{ .NetworkSettings.IPAddress }}' JC
--> 172.17.0.4
docker inspect -f '{{ .NetworkSettings.IPAddress }}' JC
- > 172.17.0.4
docker inspect -f '{{ .NetworkSettings.IPAddress }}' EC
--> 172.17.0.2
docker inspect -f '{{ .NetworkSettings.IPAddress }}' EC
- > 172.17.0.2
docker inspect -f '{{ .NetworkSettings.IPAddress }}' TC
--> 172.17.0.3
docker inspect -f '{{ .NetworkSettings.IPAddress }}' TC
- > 172.17.0.3
I can certainly ping EC from JC by IP address: docker exec JC ping -c 2 172.17.0.2
. 我当然可以通过IP地址从JC ping EC:
docker exec JC ping -c 2 172.17.0.2
。 But getting the containers to see each other by IP address does not help as my Java application needs a hostname reference as a part of its configuration. 但是让容器通过IP地址看到彼此并没有帮助,因为我的Java应用程序需要主机名引用作为其配置的一部分。
Any ideas on what's going on? 关于发生了什么的任何想法? Is it the container images themselves?
它是容器图像本身吗? Why would the busybox container image be able to ping the ElasticSearch container by name but the java container not?
为什么busybox容器映像能够按名称ping ElasticSearch容器,但java容器不能?
Some more information. 更多信息。
Any help is appreciated. 任何帮助表示赞赏。
Within the same docker daemon, use the old --link
option in order to update the /etc/hosts of each component and make sure one can ping the other: 在同一个
--link
守护程序中,使用旧的--link
选项来更新每个组件的/ etc / hosts,并确保可以ping另一个组件:
docker run -d --name EC elasticsearch:1.5.2 elasticsearch -Des.cluster.name=es
docker run -dit --name JC --link ED myapp-image
docker run --rm --name TC -it busybox:latest
Then, a docker exec JC ping -c 2 EC
should work. 然后,
docker exec JC ping -c 2 EC
应该可以工作。
If it does not, check if this isn't because of the base image and a security issue: see " Addressing Problems with Ping in Containers on Atomic Hosts ". 如果没有,请检查是否由于基本映像和安全问题:请参阅“ 解决原子主机上容器中的Ping问题 ”。
JC is based on docker/_java:8
, itself based on jessie-curl
, jessie
. JC基于
docker/_java:8
,它本身基于jessie-curl
, jessie
。
Containers in this default network are able to communicate with each other using IP addresses.
此默认网络中的容器可以使用IP地址相互通信。 Docker does not support automatic service discovery on the default bridge network.
Docker不支持默认网桥上的自动服务发现。 If you want to communicate with container names in this default bridge network, you must connect the containers via the legacy docker run --link option.
如果要与此默认桥接网络中的容器名称进行通信,则必须通过旧版docker run -link选项连接容器。 docs.docker.org .
docs.docker.org 。
It should also work using the new networking. 它也应该使用新的网络。
docker network create -d bridge non-default
docker run --net non-default ...
There isn't a specific option which applies this behavior to the default network (AFAICT from looking at docker network inspect
). 没有将此行为应用于默认网络的特定选项(通过查看
docker network inspect
AFAICT)。 I guess it's just triggered by the option "com.docker.network.bridge.default_bridge". 我猜它只是由“com.docker.network.bridge.default_bridge”选项触发。
In the first part of another question, it's suggested this was changed in Docker 1.9. 在另一个问题的第一部分中,建议在Docker 1.9中对此进行更改。 Note that Docker 1.9 was when they turned on the new networking system in the stable release.
请注意,Docker 1.9是他们在稳定版本中打开新网络系统的时候。 The section of the userguide that I quoted from above, did not exist in version 1.8.
我在上面引用的用户指南部分在1.8版中不存在。 Docker 1.9.0 "bridge" versus a custom bridge network results in difference in hosts file and SSH_CLIENT env variable
Docker 1.9.0“桥接”与自定义桥接网络导致主机文件和SSH_CLIENT env变量不同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.