How To Differentiate Between Docker Images, Containers, Stacks, Machine, Nodes and Swarms
What are they and how do they fit together?

When I was a beginning Docker half a year ago, I had many questions on how to differentiate between Docker Images, Docker Containers, Docker Stacks, Docker Machine, Docker Nodes and Docker Swarms. Today, let’s explore this diagram, which makes it easy to differentiate between them all:

Docker Images and Containers
A container is the smallest unit of the entire Docker architecture. Before a container is launched, it is called as an image. According to the definition provided in Docker Documentation, an image is an executable package including everything that’s required to run an application, from application codes, to runtime, libraries, environment variables, and configuration files. A container is a runtime instance of an image.
If you still don’t understand, let me use analogy. Imagine you’ve bought an oven and you put your food into the oven. Your food now represents the executable package, including everything needed to run an application. Before you turn on your oven, your oven is in the “OFF” state or is not performing any operation. The oven is the analogy of an image. When you turn on your oven, your oven is in the “ON” state and performing operations. The oven is now the analogy of a container.
Simply put, an image is the “non-running” unit of a container or a container is the running unit of an image.
Docker Services
In a distributed application, different pieces of the application are called “services”.
For instance, an attendance web application normally contains different types of services, like the front-ends interacting with the users, the back-ends processing the inputs from the users and storage storing the user data.
A service only runs one type of image. A single container running in a service is called a task. Refer to the diagram above — the containers under the same service are running the same image, or performing the same functionality. A service codifies an approach of how the image should be running, like the port’s numbers and the number of replicas of the containers. Scaling up a service will increase the number of containers in a service, leading to high throughput of that particular service.
The containers in a service are not necessarily all located on the same node. According to the diagram above, there are three containers deployed under Service 1, two of the containers are located on Node 1 and another is located on Node 2.
Docker Stacks
According to the definition provided in Docker Documentation, a stack is a group of interrelated services that share dependencies and can be orchestrated and scaled together. Referring to the diagram above, there are three services under a single stack. A single stack is capable of defining and coordinating the functionality of an entire application — unless the application is highly complex and needs to be split into multiple stacks.
Docker Machine
Docker Machine is a tool that lets the users install Docker Engine on virtual hosts and manage the virtual hosts with docker-machine
commands.
Docker Nodes
Docker Nodes are equivalent to virtual hosts. As shown in the diagram above, there are three virtual hosts or nodes. Each node can represent either physical or virtual machines. Again, the containers hosted on the same node are not necessarily serving the same service.
Docker Swarms
Normally, a swarm consists of multiple nodes. Some of the nodes will be chosen as managers and some of them will be chosen as workers. In this diagram, there is one manager node and two worker nodes. The manager node is responsible for managing the membership and delegation and the worker node is responsible for executing swarm services.
Conclusion
- Docker Container is a runtime instance of Docker Image.
- Docker Service can run one type of Docker Images on various containers locating on different nodes to perform the same functionality.
- Docker Stack consists of multiple Docker Services.
- Docker Machine is a tool used to install and manage virtual hosts or Docker Nodes.
- Docker Swarm contains manager nodes who manage the membership and delegation and worker nodes who run swarm services.
References
- Get Started with Docker: https://docs.docker.com/get-started/
- Swarm Mode Key Concepts: https://docs.docker.com/engine/swarm/key-concepts/