Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Swarms and Stacks: What's the difference?

I just read Docker's excellent Getting Started guide, and just wanted to confirm I understand the basic Docker parlance before I go much further. These definitions are somewhat provided in the docs, but a lot of those docs are example-based without giving concrete form to the following concepts.

As such, my understanding is that:

  • Services: Docker Services are the different components of your application: the frontend might be a React UI, the backend might be a Spring Boot web service, you might have a MySQL DB as well as a RabbitMQ broker; these would all be different Services all comprising your application.
  • Cluster: Docker Clusters are when you have a Swarm managing 1+ Services for an application across 2+ Docker Hosts; the Cluster simply refers to all the Docker Hosts where your Service containers are running.
  • Compose: Docker Compose is a tool used to manage Services, Swarms and Stacks.
  • Stack: Docker Stacks occur when a Swarm Manager is managing multiple Swarms for multiple Services, on a given Cluster, for a given application; hence the difference between a Swarm and a Stack is that a Swarm simply applies to a single Service, whereas a Stack manages multiple Swarms and hence multiple Services that all comprise a scalable and distributed application.

So I ask: am I correct in my understanding of these fundamental terms or am I misled in some way?

like image 408
smeeb Avatar asked Jun 12 '17 13:06

smeeb


People also ask

What is the purpose of a stack in docker Swarm?

Stacks allow for multiple services, which are containers distributed across a swarm, to be deployed and grouped logically. The services run in a Stack can be configured to run several replicas, which are clones of the underlying container.

What is the difference between docker and docker Swarm?

The difference between Docker Swarm and Docker Compose is that Compose is used for configuring multiple containers in the same host. Docker Swarm is different in that it is a container orchestration tool. This means that Docker Swarm lets you connect containers to multiple hosts similar to Kubernetes.

What is the difference between Docker compose and docker stack?

Docker Compose is an official tool that helps you manage your Docker containers by letting you define everything through a docker-compose. yml file. docker stack is a command that's embedded into the Docker CLI. It lets you manage a cluster of Docker containers through Docker Swarm.

What is meant by docker Swarm?

Docker Swarm is a clustering and scheduling tool for Docker containers. With Swarm, IT administrators and developers can establish and manage a cluster of Docker nodes as a single virtual system. Swarm mode also exists natively for Docker Engine, the layer between the OS and container images.


4 Answers

Services: Docker Services are the different components of your application...

A service is a an image docker swarm manages for you. You might ask it to run three instances of this image, and docker swarm will do so (if it can).

Docker Hub shows you all the different images you can run.

Cluster: Docker Clusters are when you have a Swarm managing 1+ Services for an application across 2+ Docker Hosts; the Cluster simply refers to all the Docker Hosts where your Service containers are running.

Yeah. A cluster is made up of nodes which are either workers (that run the services), or managers (control the scheduling of services across the nodes). Note that a node can be both a worker and a manager.

I'm still getting my head around managers but I believe you should aim to have an odd number of at least 3 otherwise you can have issues if a manager disappears.

Compose: Docker Compose is a tool used to manage Services, Swarms and Stacks.

Docker compose is used to combine images into a working application. It might include a front end proxy, a website and a backend database for example. This technology has nothing to do with docker swarm particularly... except you can use it to deploy your application across a swarm (https://codefresh.io/blog/deploy-docker-compose-v3-swarm-mode-cluster/)

Stack: Docker Stacks occur when a Swarm Manager is managing multiple...

Stack is used for docker cloud. This probably isn't what you are looking for :)

like image 142
Ross Dargan Avatar answered Oct 24 '22 05:10

Ross Dargan


Docker swarm is a Clustering and orchestration tool. It is used for scheduling containers across multiple nodes. You can combine multiple nodes as a cluster and then send "docker run" command to this cluster.

Docker stack is a collection of services that make up an application in a specific environment. The extension of stack file is yaml (yml also).

like image 40
Virendra Jadeja Avatar answered Oct 24 '22 07:10

Virendra Jadeja


I made this to help me understand the stack concept.

enter image description here

like image 1
rr789 Avatar answered Oct 24 '22 05:10

rr789


Swarm Mode: This refers to the overall technology for managing a multi-node environment with declarative syntax. It consists of an embedded raft database distributed across a quorum of managers, and a scheduler that is constantly correcting the difference between the current state and target state defined by the Services.

Cluster: A group of nodes managed by Swarm Mode.

Node: A single docker engine that is part of the Cluster. Each node may be a Worker or a Manager. Managers can both run a workload and they are responsible for maintaining the raft database and selecting a leader to run the scheduler.

Stack: This is mostly treated as a namespace for a collection of services, networks, and volumes deployed within Swarm Mode. At present it's a client side construct that looks for objects with a specific label. A Stack maps to a compose file deployed in Swarm Mode (docker-compose could also be used to deploy a compose file to a single docker engine as a compose project).

Service: A definition of an image, the configuration used when deploying it as a container, and where to deploy the containers within a Swarm Mode Cluster. A service may result in one or more containers with the same configuration settings. Swarm Mode will define a DNS entry that is load balanced to the containers with the service name. By combining multiple replicas and rolling updates, changes to the service can be performed without downtime.

like image 1
BMitch Avatar answered Oct 24 '22 06:10

BMitch