[英]Failed to connect service in another container by hostname with docker-compose
version: '3.7'
services:
translate:
restart: always
# Docker file here: https://github.com/mashirozx/google-translate-server/blob/master/Dockerfile
image: mashirozx/google-translate-server:latest
ports:
- "127.0.0.1:30031:30031"
command: "npm start -- --domain ${DOMAIN:-cn}"
networks:
- external_network
- internal_network
app:
image: app:dev
networks:
- external_network
- internal_network
depends_on:
- translate
links:
- "translate:translationserver"
In app
container, both hostname translate
and translationserver
is unable to resolve, and I tried to use the server public IP, http://public.IP:30031 is accessible in app
.在app
容器中,主机名translate
和translationserver
服务器都无法解析,我尝试使用服务器 public IP,http://public.IP:30031可在app
中访问。 SO the problem is the hostname not resolved in app
container.所以问题是主机名没有在app
容器中解析。
Same question, but no one solve my problem:同样的问题,但没有人解决我的问题:
docker-compose fails to resolve service hostname docker-compose 无法解析服务主机名
How do I set hostname in docker-compose? 如何在 docker-compose 中设置主机名?
links
is deprecated, since you don't need it to access other contianers in the same docker.network. links
已弃用,因为您不需要它来访问同一 docker.network 中的其他容器。
https://docs.docker.com/compose/compose-file/#links https://docs.docker.com/compose/compose-file/#links
Try removing links
and use in your app
name translate
: docker will resolve internal IP (docker vlan) to access it.尝试删除links
并在您的app
名称中使用translate
:docker 将解析内部 IP(docker vlan)以访问它。
version: '3.7'
services:
translate:
restart: always
# Docker file here: https://github.com/mashirozx/google-translate-server/blob/master/Dockerfile
image: mashirozx/google-translate-server:latest
container_name: translate
ports:
- "127.0.0.1:30031:30031"
command: "npm start -- --domain ${DOMAIN:-cn}"
networks:
- external_network
- internal_network
app:
image: app:dev
container_name: myapp
networks:
- external_network
- internal_network
depends_on:
- translate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.