Docker-Compose with Docker 1.12 “Swarm Mode”
Does anyone know how (if possible) to run docker-compose commands against a swarm using the new docker 1.12 ‘swarm mode’ swarm?
I know with the previous ‘Docker Swarm’ you could run docker-compose commands directly against the swarm by updating the DOCKER_HOST to point to the swarm master :
and then simply execute commands as if you were running them against a single instance of Docker engine.
OR is this functionality something that
docker-compose bundle is replacing?
3 Solutions collect form web for “Docker-Compose with Docker 1.12 “Swarm Mode””
I realized my question was vaguely worded and actually has two parts to it. Eventually however, I was able to figure out solutions to both issues.
1) Can you run commands directly ‘against’ a swarm / swarm-mode in Docker 1.12 running on a remote machine?
While you can’t really run commands ‘against’ a swarm you CAN run
docker service commands on the master node of a swarm in order to run services on that swarm.
You can also configure the Docker daemon (the docker daemon that is the master node of the swarm) to listen on TCP ports in order to externally expose the Docker API.
2) Can you still use docker-compose files to start services in Docker 1.12 swarm-mode?
Yes, although these features are currently part of Docker’s “experimental” features. This means you must download/install the version that includes the experimental features (check the github).
You essentially follow these instructions https://github.com/docker/docker/blob/master/experimental/docker-stacks-and-bundles.md
to go from the docker-compose.yml file to a distributed application bundle and then to an application stack (this is when your services are actually run).
$ docker-compose bundle
$ docker deploy [OPTIONS] STACK
Here’s what I did:
On my remote swarm manager node I started docker with the following options:
docker daemon -D -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 &
This configures Docker daemon to listen on the standard docker socket
WARNING : I’m not enabling TLS here just for simplicity
On my local machine I update the docker host environment variable to point at my swarm master node.
$ export DOCKER_HOST="tcp://XX.XX.XX.XX:2377"(populate with your IP)
Navigate to the directory of my docker-compose.yml file
Create a bundle file from my docker-compose.yml file. Make sure to include the
docker-compose bundle --fetch-digests -o myNewBundleFile.dab
Create an application stack from the bundle file. Do not specify the
$ docker deploy myNewBundleFile
Now I’m still experiencing some networking related issues but I have successfully gotten my service up and running from my unmodified docker-compose.yml files. The network issues I’m experiencing is documented here : https://github.com/docker/docker/issues/23901
While the official support for Swarm mode in Docker Compose is still in progress, I’ve created a simple script that takes
docker-compose.yml file and runs
docker service commands for you. See https://github.com/ddrozdov/docker-compose-swarm-mode for details.
It is not possible. Compose uses containers to create a client-side concept of a service. Docker 1.12 Swarm mode introduces a new server-side concept of a service.
You are correct that
docker-compose bundle; docker stack deploy is the way to get a Compose file running in Swarm Mode.