[英]Links between containers not working with docker-compose version 2
Linking between containers in a version 2 docker-compose file is not working. 在版本2 docker-compose文件中的容器之间的链接不起作用。
Only when using the 'old' version 1 format, I do see the link in /etc/hosts of the container. 只有在使用“旧” 版本1格式时,才会看到容器的/ etc / hosts中的链接。
I have the following basic version 2 docker-compose.yml file. 我有以下基本版本2 docker-compose.yml文件。
version: '2' services: my-app: image: tomcat:8.0 container_name: my-app1 links: - my-redis my-redis: image: redis container_name: my-redis1
When I run the following command: 当我运行以下命令时:
docker-compose up -d
I see that two containers are started, but no link is created in the /etc/hosts file: 我看到启动了两个容器,但在/ etc / hosts文件中没有创建链接 :
docker exec -it my-app1 cat /etc/hosts
127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 172.18.0.3 2abb84ccada9
From 'my-app1' I can ping the other container using the IP address of 'my-redis1', but I cannot 'ping my-redis1' (based on a name). 从'my-app1'我可以使用'my-redis1'的IP地址ping另一个容器,但我不能'ping my-redis1'(基于名称)。
What could be the problem here? 这可能是什么问题?
Additional information: 附加信息:
With version 2 of docker-compose the 'services' (containers) that are in the same network are linked between them by default. 对于docker-compose的版本2,默认情况下,同一网络中的“服务”(容器)在它们之间链接。
Using the below docker-compose.yml file 使用下面的docker-compose.yml文件
version: '2'
services:
my-app:
image: tomcat:8.0
container_name: my-app1
links:
- my-redis
my-redis:
image: redis
container_name: my-redis1
You just can execute ping my-app
from your my-redis
container and ping my-redis
from your my-app
container to check that they are linked. 您可以从my-redis
容器执行ping my-app
,并从my-app
容器中ping my-redis
以检查它们是否已链接。
For instance: 例如:
$ docker-compose up -d
$ docker exec -it my-app1 bash
# ping my-redis
You can get more information about that in the links below: https://blog.docker.com/2016/02/compose-1-6/ https://github.com/docker/compose/blob/master/docs/networking.md 您可以在以下链接中获取有关该信息的更多信息: https : //blog.docker.com/2016/02/compose-1-6/ https://github.com/docker/compose/blob/master/docs/ networking.md
The problem is the firewalld of my Fedora host. 问题是我的Fedora主机的firewalld。
With the firewall temporarily disabled ('systemctl stop firewalld', followed by 'systemctl restart docker') everything works according to the docker documentation. 暂时禁用防火墙('systemctl stop firewalld',然后是'systemctl restart docker'),一切都按照docker文档工作。
There seems to be a major problem with firewalld when used with docker, see: https://github.com/docker/docker/issues/16137 . 当与docker一起使用时,firewalld似乎存在一个主要问题,请参阅: https : //github.com/docker/docker/issues/16137 。
Note that RHEL/Centos 7 also use firewalld. 请注意,RHEL / Centos 7也使用firewalld。
-Arjen -Arjen
In my case the problem was in service name. 在我的情况下,问题是服务名称。
version: "2"
services:
my_auth_server:
build: auth-server
ports:
- "8082:8082"
my_api:
build: core-api
ports:
- "8081:8081"
links:
- my_auth_server:auth-server # <-- here changed from auth_server to auth-server
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.