Docker Community Forums

Share and learn in the Docker community.

Can docker-compose be used to run across multiple hosts?

I always thought that docker-compose is limited to deploying containers - not services - on one
host. But I came across which is saying
Running Compose on a Swarm cluster
Docker Swarm, a Docker-native clustering system, exposes the same API as a single Docker host, which means you can use Compose against a Swarm instance and run your apps across multiple hosts. How does one explain this?

You mixed up Compose (the config file format) with Docker-Compose (the cli tool)
The link refers to Compose as in the compose file format!

You first sentence about docker-compose is still valid: it is a single host multi container orchestrator
When it commes to swarm deployments, you will have to create a swarm cluster for this (docker swarm init, docker swarm join) and deploy the docker-compose.yml configuration with docker stack deploy.

They simply used the same file format and adapted it for swarm (v3 reference), while keeping compatibility with docker-compose.

For a single docker-compose. yml to deploy to multiple hosts, you need to use the standalone swarm (not the newer swarm mode, yet, this is rapidly changing). … yml into several files, one for each host, and then run multiple docker-compose up commands, with a different DOCKER_HOST value defined for each.