gpt4 book ai didi

docker - 我想在Docker-Swarm中将2个容器彼此连接

转载 作者:行者123 更新时间:2023-12-02 21:31:04 24 4
gpt4 key购买 nike

我想将两个容器相互连接...我从创建覆盖网络mynet开始:

docker network create -d overlay mynet
之后,我创建了第一个服务 activemq:
docker service create --name activemq -p 61616:61616 -p 8161:8161  --replicas 1 --network mynet rmohr/activemq
这将启动并运行良好,我也可以访问WebUI http:// localhost:8161 / admin /
现在,我要启动服务 TimeService,容器中具有以下设置:
docker service create --name timeservice -p 7000:7000  --replicas 1 --network mynet ni920/timeserviceplain:latest
java.naming.provider.url=tcp://localhost:61616
java.naming.user=admin
java.naming.password=admin
io.jexxa.rest.host=0.0.0.0
io.jexxa.rest.port=7000
因此,它应该通过 tcp://localhost:61616ActiveMQ连接,但事实并非如此。
你们有什么线索,我应该尝试在无 Swarm环境中或在 Kubernetes-Pod环境中正常进行通信的方式吗?

最佳答案

如果您希望容器相互通信,可以使用它们的名称,然后让网络驱动程序解析其ip。
这是docker docs中的network driver summary:

  • User-defined bridge networks are best when you need multiple containers to communicate on the same Docker host.
  • Host networks are best when the network stack should not be isolated from the Docker host, but you want other aspects of the container to be isolated.
  • Overlay networks are best when you need containers running on different Docker hosts to communicate, or when multiple applications work together using swarm services.
  • Macvlan networks are best when you are migrating from a VM setup or need your containers to look like physical hosts on your network, each with a unique MAC address.
  • Third-party network plugins allow you to integrate Docker with specialized network stacks.


在您的情况下,请将 本地主机替换为服务名称 activemq
java.naming.provider.url=tcp://activemq:61616
.
.

关于docker - 我想在Docker-Swarm中将2个容器彼此连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64458714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com