首页 > 解决方案 > 我可以在 docker swarm 中隔离一对服务吗?

问题描述

我正在使用 docker swarm 构建一个网络应用程序。

管理器机器将具有数据库和负载平衡器。接下来我有两个软件:tornado 服务器,它充当用户和节点服务器之间的中间层。他们应该总是一起服务。一台龙卷风服务器应该始终与一台节点服务器通信。

我希望容器尽可能隔离(以保持可扩展性),但我如何确保这种通信?

现在我的方法是构建两个单独的图像 - 一个用于龙卷风,一个用于节点,然后创建连接它们的多阶段容器。我觉得这不是最佳选择,因为我必须在CMD.

什么是优选的解决方案?您可以强制 docker 耦合图像(例如,不指定 IP)吗?

标签: dockertornadodocker-swarm

解决方案


There is a link feature in docker compose files: https://docs.docker.com/compose/compose-file/#links. But recently Docker marked it as deprecated and suggests using user-defined networks: https://docs.docker.com/network/.

P.S: Also pay attention to the notes:

- If you define both links and networks, services with links between them must share at least one network in common to communicate.

- This option is ignored when deploying a stack in swarm mode with a (version 3) Compose file.

推荐阅读