Compose: Using docker-compose with docker-engine's swarm mode

Created on 29 Jun 2016  路  26Comments  路  Source: docker/compose

Hi,

Could someone point me to instructions on using docker-compose to schedule services on the new docker-engine swarm mode cluster?

When I try to do a:

  1. eval $(docker-machine env [swarm-master-hostname])
  2. docker-compose up
  3. All the services defined in my docker-compose.yaml file get started up as containers on the single host.

How can I get the services defined in my docker-compose file started up as "services" in swarm mode?

Thanks!
-Selvi

Most helpful comment

when will docker compose support the integration of docker in swarm model?

All 26 comments

From what I can tell, docker-compose is not yet compatible with the new swarm-mode. It's unclear when these integrations will be available.

Swarm mode is not supported by compose yet. Compose basically does a run on the containers in your compose file. In swarm mode run only schedules containers on the daemon to which your client is connected.

You can use the new bundle feature (only in compose > 1.8) to get what you want though. Run docker-compose bundle in your compose folder and it will generate a something.dsb file. Then you can run docker deploy something (no extension). This will schedule your containers across the swarm.

Thanks @johnharris85. The new workflow you've suggested works for me. So my follow up question is: Is this the new intended workflow henceforth or will docker-compose be updated to run services directly?

@selvik I would _expect_ that compose would get some native integration with swarm mode, but don't have any specific details or timeframes.

so. just to sum up.

it means docker-compose - looks useless for more than one node :( again.
and talks about backward compatibility from https://www.youtube.com/watch?v=F7hoq0KwHD4 ... fake.

@freeseacher Compose 1.8 and Engine 1.12 in normal (non-swarm) mode still work fine together, so backward compatibility has been 100% preserved - if you've seen behaviour in the RCs that suggests otherwise, please open an issue for it.

when will docker compose support the integration of docker in swarm model?

Hi,

according to the doc compose should work with swarm mode. However I cannot make it work, here are is my try:

$ docker -v
Docker version 1.12.0, build 8eab29e

$ docker-machine -v
docker-machine version 0.8.1, build 41b3b25

$ docker-machine create --driver virtualbox manager1
Running pre-create checks...
Creating machine...
(manager1) Copying /Users/mmiglier/.docker/machine/cache/boot2docker.iso to /Users/mmiglier/.docker/machine/machines/manager1/boot2docker.iso...
(manager1) Creating VirtualBox VM...
(manager1) Creating SSH key...
(manager1) Starting the VM...
(manager1) Check network to re-create if needed...
(manager1) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env manager1

$ docker-machine create --driver virtualbox worker1
Running pre-create checks...
Creating machine...
(worker1) Copying /Users/mmiglier/.docker/machine/cache/boot2docker.iso to /Users/mmiglier/.docker/machine/machines/worker1/boot2docker.iso...
(worker1) Creating VirtualBox VM...
(worker1) Creating SSH key...
(worker1) Starting the VM...
(worker1) Check network to re-create if needed...
(worker1) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env worker1

$ eval "$(docker-machine env manager1)"
$ docker-machine ls
NAME       ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
manager1   *        virtualbox   Running   tcp://192.168.99.100:2376           v1.12.1
worker1    -        virtualbox   Running   tcp://192.168.99.101:2376           v1.12.1

$ docker swarm init --advertise-addr 192.168.99.100
Swarm initialized: current node (by7rw6ua88az3ayypu42l8hpe) is now a manager.

To add a worker to this swarm, run the following command:
    docker swarm join \
    --token SWMTKN-1-0rdc568jregv3ozuv9r5npezox4dndd269pwsu052dpu3qgb7c-3k4flh5i8sr3byjklkp6zvqu6 \
    192.168.99.100:2377

To add a manager to this swarm, run the following command:
    docker swarm join \
    --token SWMTKN-1-0rdc568jregv3ozuv9r5npezox4dndd269pwsu052dpu3qgb7c-8k2juvp536bk0zwmzq8hfms7x \
    192.168.99.100:2377

$ eval "$(docker-machine env worker1)"
$ docker swarm join --token SWMTKN-1-0rdc568jregv3ozuv9r5npezox4dndd269pwsu052dpu3qgb7c-3k4flh5i8sr3byjklkp6zvqu6 192.168.99.100:2377

$ eval "$(docker-machine env manager1)"
$ docker node ls
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
9cg3wmh7abj910fnrvxf415kh    worker1   Ready   Active
by7rw6ua88az3ayypu42l8hpe *  manager1  Ready   Active        Leader

$ docker-machine env --swarm manager1
Error checking TLS connection: "manager1" is not a swarm master. The --swarm flag is intended for use with swarm masters

What am I doing wrong?

Thanks!

Marco

One issue I've seen in looking into this myself is that I don't see anything in any upcoming Milestones nor can I find any issues that indicate active discussions/development in introducing support for Docker Swarm Mode and Docker Compose. Anyone?

Received this error running "docker-compose bundle":

docker-compose bundle
ERROR: Service 'netstats' doesn't define an image tag. An image name is required to generate a proper image digest for the bundle. Specify an image repo and tag with the 'image' option.

Bundles use digests to specify the images, and an image only gets a digest once it has been pushed to a Registry.

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 would also be nice, if containers inside a docker-compose.yml can attach to an existing docker swarm overlay network.
Right now this does not seem to work, as docker deploy will create new networks for projectName.dba named: projectName_default and any other networks defined in the docker-compose.yml, e.g. projectName_frontend.

  • What I would like is that container can attach to the swarm network frontend
  • This is only possible using docker service create..., but this defeats docker-compose and it's dabs.

The scenario is:

  • Have a global jwilder/nginx-proxy service running with -p 80:80 -p 443:443 and bind-mount of TLS-certs. The nginx proxy runs inside it's own network, frontend and does TLS-termination
  • Add a separate docker-compose with the actual services behind the reverse-proxy, whereas the services, which need tls-termination, attach to the frontend network and their default network.

The other wish would be:

  • docker deploy will not use an existing swarm network, which happens to have the same name (e.g. projectName_default). It is only possible for docker deploy to create such a network.
  • This is fine with me, but it is not clear, whether a docker deploy-created network has the --option=encrypted` or not ?

If somebody could clarify, if docker-compose networks in Swarm-Mode are encrypted, would be nice.

@johnharris85 I think Docker Inc. wanted to quickly come up with a simpler alternative to kubernetes so that it can latch on to the customers who were already familiar with docker and were considering options for container orchestration. That seems to be the most imp reason for releasing swarm mode as part of docker core without thinking about all the scenarios people will come up with in production deployment.

It seems that Docker will make everything compatible with "services" and "swarm-mode". So, soon we should be able to orchestrate complex services using docker-compose that leverages swarm-mode underneath.

@henaras that sounds nice, but speculative. Can you point to any recent developments that make you think that this is coming "soon", as you said?

@brettdh Docker 1.13 will add the ability to do stack deployments directly from a Docker Compose file (version 3), instead of just from Docker Application Bundle (.dab) files. See docker/docker#27998 for the PR.

@kinghuang That's great news; thanks for the detail. I do recall seeing that PR, now that you mention it, but I didn't see a new RC for Docker Compose yet, so I wasn't sure what the support was going to be.

I think I'm generally unclear on the exact relationship between bundles, stacks, services, and docker-compose, but I imagine this will become clearer as the 1.13 release comes.

Hoping to see this feature officially supported as soon as possible! Docker Swarm Mode has a lot of advantages like load balancing and rolling updates, and Compose let me define my environment in an easy way, so using the two of them would be really nice!

I am confused with http://docs.master.dockerproject.org/compose/swarm/. This issue and the link attached is contradicting, is n't it?. This link provides the way to use compose with swarm mode. Then what is this issue for? or Am I missing something?

@srinivasthallapalli it seems that there are so many compose names for docker.
And we gone another one in 1.13 that introduces target_num_containers that simply does not exists in that one or libcompose.

@srinivasthallapalli That would appear to refer to swarm as opposed to swarm mode (i.e. the old way of doing things) - from that page if you click the link mentioning Docker Swarm, you get presented with this message:

Advisory: See Swarm mode overview for the orchestration features introduced in Docker Engine 1.12. Only refer to the Docker Swarm documents below for information on the standalone Swarm product.

Since Docker 1.13 you can use --compose-file option to deploy docker-compose in the swarm mode like this:
docker stack deploy --compose-file=docker-compose.yml my_stack

https://blog.docker.com/2017/01/whats-new-in-docker-1-13/

Please close? It sounds like @pestrov has responded with a fix.

Thanks everyone. As @pestrov pointed out, use docker stack and Compose file v3 for Swarm mode. See the docs for more info.

Hello Folks,
I understand that the issue is marked as resolved by referencing "docker stack deploy" command. But can someone explain how it fits into the ansible scripting. I am currently using docker_service command in ansible to deploy to swarm cluster and it always gets deployed as docker run containers because of docker-compose. Any help in deployment to swarm cluster through ansbile will be appreciated.

Was this page helpful?
0 / 5 - 0 ratings