zapatilla
zapatilla

Reputation: 1853

How do I run docker-compose up on a a docker-swarm?

I'm new to Docker and trying to get started by deploying locally a hello-world Flask app on Docker-Swarm.

So far I have my Flask app, a Dockerfile, and a docker-compose.yml file.

version: "3"
services:
  webapp:
    build: .
    ports:
      - "5000:5000"

docker-compose up works fine and deploys my Flask app.

I have started a Docker Swarm with docker swarm init, which I understand created a swarm with a single node:

ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
efcs0tef4eny6472eiffiugqp *  moby      Ready   Active        Leader

Now, I don't want workers or anything else, just a single node (the manager node created by default), and deploy my image there.

Looking at these instructions https://docs.docker.com/get-started/part4/#create-a-cluster it seems like I have to create a VM driver, then scp my files there, and ssh to run docker-compose up. Is that the normal way of working? Why do I need a VM? Can't I just run docker-compose up on the swarm manager? I didn't find a way to do so, so I'm guessing I'm missing something.

Upvotes: 1

Views: 2922

Answers (1)

BMitch
BMitch

Reputation: 265130

Running docker-compose up will create individual containers directly on the host.

With swarm mode, all the commands to manage containers have shifted to docker stack and docker service which manage containers across multiple hosts. The docker stack deploy command accepts a compose file with the -c arg, so you would run the following on a manager node:

docker stack deploy -c docker-compose.yml stack_name

to create a stack named "stack_name" based on the version 3 yml file. This command works the same regardless of whether you have one node or a large cluster managed by your swarm.

Upvotes: 5

Related Questions