我已经成功地在 Digital Ocean 机器上创建了自己的 Docker Swarm,而没有使用“docker-machine create”docker SWARM 钩子。我不使用这些钩子的动机是为了提供更好的引导和与我的 Consul 提供者以及其他东西的集成。
我面临的问题是“docker -H XXX.XXX.XXX.XXX:3376 ps”有效意味着我的 SWARM 已正确初始化,但由于“docker-machine ls”,我无法连接“docker-compose”无法识别 SWARM。我已通读 docker-machine 代码,试图找出“docker-machine ls”如何识别 SWARM 但找不到它。这是我的相关信息
docker-compose-master.yml
...
swarm:
container_name: swarm-agent-master
hostname: swarm-master-server-1
image: swarm
ports:
- "<MASTER_IP>:3376:2375"
volumes:
- "/etc/docker:/certs"
command: manage -H tcp://0.0.0.0:2375 --replication --advertise <MASTER_IP>:3376 --tlsverify --tlscacert /certs/ca.pem --tlscert /certs/server.pem --tlskey /certs/server-key.pem consul://consul:8500
links:
- consul
environment:
SERVICE_NAME: manager
SERVICE_TAGS: swarm
restart: "always"
...
docker-compose-client.yml
...
swarm:
container_name: swarm-agent
hostname: swarm-client-1
image: swarm
command: join --advertise <AGENT_IP>:2376 consul://consul:8500
links:
- consul
environment:
SERVICE_NAME: agent
SERVICE_TAGS: swarm
restart: "always"
...
请参阅以下输出
%> docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
swarm-master-server-1 digitalocean Running tcp://<MASTER_IP>:2376
swarm-client-1 digitalocean Running tcp://<AGENT_IP>:2376
%> eval "$(docker-machine env --swarm swarm-master-server-1)"
swarm-master-server-1 is not a swarm master
%> eval "$(docker-machine env swarm-master-server-1)"
%> docker run swarm list consul://<CONSUL_IP>:8500
<AGENT_IP>:2376
%> docker -H tcp://<MASTER_IP>:3376 ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
<lists jobs running on AGENT>
%> docker -H tcp://<MASTER_IP>:3376 info
Containers: 3
Images: 4
Role: replica
Primary: <MASTER_IP>:3376
Strategy: spread
Filters: affinity, health, constraint, port, dependency
Nodes: 1
swarm-client-1: <AGENT_IP>:2376
└ Containers: 4
└ Reserved CPUs: 0 / 1
└ Reserved Memory: 0 B / 514.5 MiB
└ Labels: executiondriver=native-0.2, kernelversion=3.13.0-57-generic, operatingsystem=Ubuntu 14.04.3 LTS, provider=digitalocean, storagedriver=aufs
CPUs: 1
Total Memory: X GiB
Name: swarm-master-server-1
有谁知道我需要做些什么才能让 Docker Machine 识别我有一个 SWARM 以便我可以连接和使用 Docker Compose?
或者,有谁知道我如何在没有 docker-machine 的情况下将 docker compose 指向 SWARM?