Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :
export DOCKER_HOST="tcp://123.123.123.123:3375"
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?

like image 899
Fabian Avatar asked Jul 13 '16 14:07

Fabian


People also ask

Does Docker Compose use Swarm?

Start the app with docker-compose up . This builds the web app image, pulls the Redis image if you don't already have it, and creates two containers. You see a warning about the Engine being in swarm mode. This is because Compose doesn't take advantage of swarm mode, and deploys everything to a single node.

How do I enable docker in swarm mode?

When you run the command to create a swarm, the Docker Engine starts running in swarm mode. Run docker swarm init to create a single-node swarm on the current node. The Engine sets up the swarm as follows: switches the current node into swarm mode.

Is docker swarm mode deprecated?

Docker Swarm is not being deprecated, and is still a viable method for Docker multi-host orchestration, but Docker Swarm Mode (which uses the Swarmkit libraries under the hood) is the recommended way to begin a new Docker project where orchestration over multiple hosts is required.

Is docker swarm discontinued?

Important note: At the time of this writing, Docker Swarm is not dead. It is included in the Docker Community edition and Docker has not announced plans to deprecate it.


3 Answers

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:

  1. 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 unix:///var/run/docker.sock AND on localhost:2375.
    WARNING : I'm not enabling TLS here just for simplicity

  2. 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)

  3. Navigate to the directory of my docker-compose.yml file

  4. Create a bundle file from my docker-compose.yml file. Make sure to include the .dab extension. docker-compose bundle --fetch-digests -o myNewBundleFile.dab

  5. Create an application stack from the bundle file. Do not specify the .dab extension here.
    $ 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

like image 78
Fabian Avatar answered Sep 17 '22 18:09

Fabian


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.

like image 31
Dmitry Avatar answered Sep 21 '22 18:09

Dmitry


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.

like image 29
dnephin Avatar answered Sep 21 '22 18:09

dnephin