docker - 我可以在 docker swarm 中隔离一对服务吗?
问题描述
我正在使用 docker swarm 构建一个网络应用程序。
管理器机器将具有数据库和负载平衡器。接下来我有两个软件:tornado 服务器,它充当用户和节点服务器之间的中间层。他们应该总是一起服务。一台龙卷风服务器应该始终与一台节点服务器通信。
我希望容器尽可能隔离(以保持可扩展性),但我如何确保这种通信?
现在我的方法是构建两个单独的图像 - 一个用于龙卷风,一个用于节点,然后创建连接它们的多阶段容器。我觉得这不是最佳选择,因为我必须在CMD
.
什么是优选的解决方案?您可以强制 docker 耦合图像(例如,不指定 IP)吗?
解决方案
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.
推荐阅读
- leaflet - setView 是否受 CRS 更改的影响?
- python - 向字符串添加符号 N 次的 Pythonic 方式
- javascript - 如何用相同的元素填充数组?
- r - ggalluvial中的矩形(地层)顺序没有最小化交叉
- python - 如何从 Python 中的 SQL 列中选择值
- wpf - WPF DependencyProperty:如何指定 PropertyChangedCallback 的 OPOSITE 动作?
- java - 示例文件不适用于 junit 测试用例
- python - 如何读取二进制文件并将其转换为 Python 中的文本
- javascript - 使用时多次调用useEffect
或 history.push() - html - 响应式 html 锚点的最佳实践