[英]Docker-compose access LAN from containers
Suppose I have 2 services in my docker-compose: 假设我在docker-compose中有2个服务:
version: "2.4"
services:
postgres:
build:
context: .
dockerfile: ./docker_config/dockerfiles/postgres.Dockerfile
volumes:
- ./docker_volumes/db/postgresql:/var/lib/postgresql
initializer:
build:
context: .
dockerfile: ./docker_config/dockerfiles/initializer.Dockerfile
depends_on: postgres
initializer
accesses postgres
using "postgres"
hostname in the network created for this docker-compose file, but now I want initializer
to also interact with some host in LAN, which initializer
can't access now (all requests just time out). initializer
访问postgres
使用"postgres"
这个泊坞窗,撰写文件创建的网络中的主机名,但现在我想initializer
也有一些局域网中的主机,它们相互作用initializer
现在不能访问(所有请求都只是超时)。
I tried using network-mode: bridge
on both containers and on initializer
only, and LAN access worked, but initializer
could not access postgres
in these cases. 我尝试使用
network-mode: bridge
仅在容器和initializer
上network-mode: bridge
,并且可以进行LAN访问,但是在这些情况下initializer
无法访问postgres
。
How to make both LAN and postgres
container accessible from initializer
container? 如何使LAN和
postgres
容器都可以从initializer
容器访问?
The solution was to add another network to initializer
service, not override the default. 解决方案是将另一个网络添加到
initializer
服务,而不要覆盖默认服务。 The code for clarity: 清楚的代码:
version: "2.4"
networks:
lan_access:
driver: bridge
services:
postgres:
build:
context: .
dockerfile: ./docker_config/dockerfiles/postgres.Dockerfile
volumes:
- ./docker_volumes/db/postgresql:/var/lib/postgresql
initializer:
build:
context: .
dockerfile: ./docker_config/dockerfiles/initializer.Dockerfile
depends_on: postgres
networks:
- lan_access
- default
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.