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 https://docs.docker.com/compose/production/ 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.

Hello, meyay. I want to learn that if the “docker stack” can help achieve that arrange automatically containers to multi-hosts relying on load-balance. In other words, I want to distribute containers as evenly as possible across multiple hosts, using one docker-compose.yaml file.

that’s what it does :slight_smile:

see: https://docs.docker.com/engine/swarm/key-concepts/#services-and-tasks