问题
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?
回答1:
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...
回答2:
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
来源:https://stackoverflow.com/questions/43875117/what-benefits-does-docker-compose-have-over-docker-swarm-and-docker-stack