What benefits does Docker Compose have over Docker Swarm and Docker Stack?
Asked Answered
D

2

12

From what I read it seems that Docker-Compose is a tool to create multiple containers on a single host while Docker Swarm is a tool that can do the exact same thing but with more control and on multiple hosts with the help of Docker Stack. I went through the tutorial and also came across this thread:

docker-compose.yml vs docker-stack.yml what difference?

And I'm coming to the conclusion that there's no reason to ever use Docker-Compose when you can use Docker Swarm with Docker Stack. They can even use the same docker-compose.yml.

It seems that Docker-compose came before the swarm and stack and maybe the new solution of swarm + stack makes compose obsolete, but it still remains for legacy reasons. Is this thinking correct? If not, what benefits does Docker-Compose have over Docker Swarm and Docker Stack in terms of making a development or production environment?

Deauville answered 9/5, 2017 at 16:22 Comment(1)
If you are working with more than 'toy' or sample containers, then you will find compose is lighter weight (faster start times) and requires less memory than Stack. Of course, it is also a separate install which I believe to be python-based. Whenever possible, I would go with Stack - it is built-in, will likely get better support and newer features.Dacosta
R
10

It seems that Docker-compose came before the swarm and stack and maybe the new solution of swarm + stack makes compose obsolete, but it still remains for legacy reasons. Is this thinking correct?

In short, yes. Compose came before all the Swarm stuff (it originated as a 3rd party utility called fig). To make matters worse, there are even two different Swarms, old Swarm (the one that was a separate tool) and Swarm Mode (which is built into the docker binary these days).

It seems to be evolving into services and deployment concepts that get built into Docker. But I would guess Docker Compose and the Swarm Mode deployment stuff will live side by side for a while.

It is also beneficial to know that Docker Compose underpinnings live as a library called libcompose (https://github.com/docker/libcompose) which other 3rd party utilities make use of to support the docker-compose.yml file format for deploying (see Rancher and rancher-compose as an example). I would imagine they would make an effort to continue support for libcompose.

I am unclear if the Docker Swarm deployment stuff actually uses libcompose. In my cursory searches, it would appear that Swarm Mode does not implement libcompose and does its own thing. I am not sure how this relates to the future of Docker Compose and libcompose. Interpret as you see fit...

Riccardo answered 9/5, 2017 at 17:21 Comment(1)
There are a few keys not yet supported in docker stack deploy -c, particularly build so you have to pre-build the images. And docker stack deploy requires a Swarm to deploy to, even if it's just the local node. That said, docker stack deploy -c using a compose file syntax supports almost everything, plus supporting the deploy key.Avis
W
3

From what I have found: What's the difference between Docker Swarm, Docker Compose and Docker Networks?

Docker Compose is a client side tool that allows you to run an application stack with multiple components.

So in our scenario you would use Docker Compose to achieve - #2*¹. You will define a spec file where you would define how a container has to built for each of your components - db, app and web tier. You can also specify how will those interact with each other. How many instance of each and many other things.

*¹ Now you have a requirement to start an application stack which has web tier, app tier and db tier.


Compose is a tool for defining and running multi-container Docker applications.

Docker Swarm is a server side feature that enables you to:

  • A swarm is a cluster of docker nodes (machines) that act as underlying resources for starting multiple container. One can orchestrate and deploy services across the swarm.

    You can combine multiple nodes as a cluster and then send “docker run” command to this cluster (actually to the Swarm manager node) Swarm will handle scheduling(starting) this container on one of the nodes.

  • Allow containers across all nodes to communicate with one another

View official documentation at: Swarm mode overview & Docker Compose

Warrior answered 11/7, 2017 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.