Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 976
dayuloli Avatar asked Mar 29 '17 16:03

dayuloli


People also ask

What is a compose file?

The Compose file provides a way to document and configure all of the application's service dependencies (databases, queues, caches, web service APIs, etc). Using the Compose command line tool you can create and start one or more containers for each dependency with a single command ( docker-compose up ).

What is a docker stack file?

Docker Stack is run across a Docker Swarm, which is essentially a group of machines running the Docker daemon, which are grouped together, essentially pooling resources. Stacks allow for multiple services, which are containers distributed across a swarm, to be deployed and grouped logically.

What is stack yml?

A stack is a collection of services that make up an application in a specific environment. Learn more about stacks for Docker Cloud here. A stack file is a file in YAML format that defines one or more services, similar to a docker-compose. yml file for Docker Compose but with a few extensions.

Why we use Docker compose file?

Docker Compose is a tool that was developed to help define and share multi-container applications. With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down.


1 Answers

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/

like image 69
Roman Mik Avatar answered Sep 21 '22 08:09

Roman Mik