What's the difference between a stack file and a Compose file?

dayuloli picture dayuloli · Mar 29, 2017 · Viewed 18.4k times · Source

I'm learning about using Docker Compose to deploy applications in multiple containers, across multiple hosts. And I have come across two configuration files - stack file, and Compose file.

From the Cloud stack file YAML reference, it states a stack file is a file in YAML format that defines one or more services, similar to a docker-compose.yml file but with a few extensions.

And from this post, it states that stacks are very similar to docker-compose except they define services while docker-compose defines containers.

They look very similar, so I am wondering when I would use the stack file, and when to use the Compose file?

Answer

Roman Mik picture Roman Mik · Mar 29, 2017

Conceptually, both files serve the same purpose - deployment and configuration of your containers on docker engines.

Docker-compose tool was created first and its purpose is "for defining and running multi-container Docker applications" on a single docker engine. (see docker compose overview )

You use docker-compose up to create/update your containers, networks, volumes and so on.

Where Docker Stack is used in Docker Swarm (Docker's orchestration and scheduling tool) and, therefore, it has additional configuration parameters (i.e. replicas, deploy, roles) that are not needed on a single docker engine.

The stack file is interpreted by docker stack command. This command can be invoked from a docker swarm manager only.

You can convert docker-compose.yml to docker-cloud.yml and back. However, as stated in your question, you must pay attention to the differences. Also, you need to keep in mind that there're different versions for docker-compose. Presently, the latest version is version 3. (https://docs.docker.com/compose/compose-file/)

Edit: An interesting blog, that might help to understand the differences, can be found here https://blog.nimbleci.com/2016/09/14/docker-stacks-and-why-we-need-them/