简体   繁体   English

让docker容器按名称相互查看(ping)的问题

[英]Problems getting docker containers to see (ping) each other by name

I have three docker containers, 我有三个码头工人,

  1. java container (JC): for my java application (spring boot) java容器(JC):用于我的java应用程序(spring boot)
  2. elasticsearch container (EC): for ElasticSearch elasticsearch container(EC):用于ElasticSearch
  3. test container (TC): testing container to troubleshoot with ping test 测试容器(TC):使用ping测试对测试容器进行故障排除

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. 这是我如何启动容器。

  1. docker run -dit --name JC myapp-image
  2. docker run -d --name EC elasticsearch:1.5.2 elasticsearch -Des.cluster.name=es
  3. 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地址如下。

  1. docker inspect -f '{{ .NetworkSettings.IPAddress }}' JC --> 172.17.0.4 docker inspect -f '{{ .NetworkSettings.IPAddress }}' JC - > 172.17.0.4
  2. docker inspect -f '{{ .NetworkSettings.IPAddress }}' EC --> 172.17.0.2 docker inspect -f '{{ .NetworkSettings.IPAddress }}' EC - > 172.17.0.2
  3. 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. 更多信息。

  • VirtualBox 5.0.10 VirtualBox 5.0.10
  • Docker 1.9.1 Docker 1.9.1
  • Weave 1.4.0 编织1.4.0
  • CentOS 7.1.1503 CentOS 7.1.1503
  • I am running docker inside a CentOS VM on a Windows 10 desktop as a staging environment before deployment to AWS 在部署到AWS之前,我在Windows 10桌面上的CentOS VM中运行docker作为暂存环境

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-curljessie

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.

相关问题 如何让两个Docker容器可以互相ping通 - How to let two docker containers can ping each other 如何启用Docker容器通过其主机名相互ping通? - How to enable docker containers ping each other via their host names? Docker 容器在 docker compose 中无法看到彼此,主机也无法看到 - Docker containers are not able to see each other in docker compose, nor is host 如何设置两个 docker 容器,以便它们可以相互看到? - How do I setup two docker containers, such that they can see each other? 如何通过主机名ping docker网络中的其他容器? - How can I ping other containers in a docker network through their hostname? 众所周知的“Docker容器看不到彼此”的问题 - The well-known 'Docker containers don't see each other' problem docker撰写网络版本3 –除非使用公共IP,否则容器无法互相看到? - docker compose network version 3 – containers can't see each other unless using public IP? docker 同一网络上的容器(来自撰写)看不到对方 - docker containers on the same net (from compose) don't see each other 为什么 docker 容器无法通过默认网络名称中的容器名称相互 ping 通,如网桥和驱动程序网桥 - Why docker containers are not pingable to each other through container name in the default network name as bridge and driver bridge 为什么我的Docker容器不互相通信 - Why will my Docker containers not talk to each other
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM