我正在尝试使用 docker 设置一个 swarm,但我在容器之间进行通信时遇到了问题。我有 5 个节点的集群。1名经理和4名工人。
3 个应用程序:redis、splash、myapp
myapp 必须在 4 名工人身上
redis,溅到经理身上
myapp 必须能够与 redis 和 splash 通信
我尝试使用容器名称,但它不起作用。它将容器名称解析为不同的 IP。
ping splash # return a different ip than the container actually has
我正在部署运行 swarm 使用docker stack
docker stack deploy -c docker-stack.yml myapp
它们之间的链接容器也不起作用。有任何想法吗 ?我错过了什么吗?
root@swarm-manager:~# docker version
Client:
Version: 17.09.0-ce
API version: 1.32
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:42:18 2017
OS/Arch: linux/amd64
Server:
Version: 17.09.0-ce
API version: 1.32 (minimum version 1.12)
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:40:56 2017
OS/Arch: linux/amd64
Experimental: false
docker-stack.yml 包含:
version: "3"
services:
splash:
container_name: splash
image: scrapinghub/splash
ports:
- 8050:8050
- 5023:5023
deploy:
mode: global
placement:
constraints:
- node.role == manager
redis:
container_name: redis
image: redis
ports:
- 6379:6379
deploy:
mode: global
placement:
constraints:
- node.role == manager
myapp:
container_name: myapp
image: myapp_image:latest
environment:
REDIS_ENDPOINT: redis:6379
SPLASH_ENDPOINT: splash:8050
deploy:
mode: global
placement:
constraints:
- node.role == worker
entrypoint:
- ping google.com
- - 编辑 - -
我也试过卷曲。没用。
docker stack deploy -c docker-stack.yml myapp
Creating network myapp_default
Creating service myapp_splash
Creating service myapp_redis
Creating service myapp_myapp
curl http://myapp_splash:8050
curl: (7) Failed to connect to myapp_splash port 8050: No route to host
curl http://splash:8050
curl: (7) Failed to connect to splash port 8050: No route to host
有效的是获取 splash 的实际容器名称,这是一些随机生成的字符串。
curl http://myapp_splash.d7bn0dpei9ijpba4q41vpl4zz.tuk1cimht99at9g0au8vj9lkz:8050
但这并没有真正帮助我。