Docker 服务在重新创建时无法相互解析
Docker services not resolving each other when recreated
我有两个 swarm 服务是这样启动的:
docker service create --replicas 2 \
--publish 8000 \
--network example \
--detach \
--name="user_service" example.com/user_service:prod
docker service create --replicas 2 \
--publish 8000 \
--network example \
--detach \
--name="company_service" example.com/company_service:prod
当我进入 user_service
容器内部并向 company_service
发出请求时,我得到:
curl http://company_service:8000
# Returns
{"name": "Company Service"}
但是,当我像这样删除 company_service
时
docker service rm company_service
然后用开头的命令重新创建。当我尝试从 user_service
发出请求时,我得到:
curl http://company_service:8000
curl: (7) Failed to connect to company_service port 8000: Connection refused
如何强制同一网络中的所有现有服务重新解析重新创建的服务?
将“user_service”和“company_service”服务附加到一个网络(overlay),然后您可以通过他们的名字相互通信。
我有两个 swarm 服务是这样启动的:
docker service create --replicas 2 \
--publish 8000 \
--network example \
--detach \
--name="user_service" example.com/user_service:prod
docker service create --replicas 2 \
--publish 8000 \
--network example \
--detach \
--name="company_service" example.com/company_service:prod
当我进入 user_service
容器内部并向 company_service
发出请求时,我得到:
curl http://company_service:8000
# Returns
{"name": "Company Service"}
但是,当我像这样删除 company_service
时
docker service rm company_service
然后用开头的命令重新创建。当我尝试从 user_service
发出请求时,我得到:
curl http://company_service:8000
curl: (7) Failed to connect to company_service port 8000: Connection refused
如何强制同一网络中的所有现有服务重新解析重新创建的服务?
将“user_service”和“company_service”服务附加到一个网络(overlay),然后您可以通过他们的名字相互通信。