【发布时间】:2023-03-04 13:53:02
【问题描述】:
我有以下 docker-compose.yml,但需要对公共/私有网络拆分进行建模,其中 Redis 实例只能由 localhost 访问。
version: "2.2" # for compatibility, I can upgrade if needed
services:
nginx:
image: nginx
ports:
- 8080:80
redis:
image: redis
ports:
- 6379:6379
如果我需要将其限制为只能在 docker 网络中访问,这似乎很简单。考虑:
version: "2.2"
services:
nginx:
image: nginx
ports:
- 8080:80
networks:
- frontend
- backend
redis:
image: redis
ports:
- 6379:6379
networks:
- backend
networks:
frontend: {}
backend:
internal: true
但是,我们的本地 Web 开发人员在本地构建、运行和调试时需要能够从其主机(在 docker 网络之外)访问该 Redis 实例。
【问题讨论】:
-
您的意思是“一些志愿者将在他的机器上运行容器化的 redis,而其他团队成员将能够访问该 redis ?!”。对吗?
-
“其他团队成员将能够访问该 Redis”是我们想要避免的场景。理想状态是每个开发人员都运行自己的堆栈(这里省略了更多部分)但无法连接到其他开发人员的后端。
-
我会给你美味的答案
-
查看@AdamSmith 下方的答案。祝你好运!