Docker is an open source platform that enables developers to build, deploy, run, update and manage containerized applications.
Containers are something like a virtual machine, it has its operating system and all, except that unlike virtual machines they don’t simulate the entire computer, but rather create a sand boxed environment that pretends to be a virtual machine.
A running (or stopped) instance of an image (virtual filesystem that has application code, dependencies, operating system, configuration files, binary files, libraries and frameworks, system libraries**)** is called a container.
More correctly, In docker, an image is an immutable file that holds the source code and information needed for a docker app to run. It can exist independent of a container. Docker containers are virtualized environments created during runtime and require images to run. You have an image, which is a set of layers as you describe. If you start this image, you have a running container of this image. You can have many running containers of the same image.
And the stack has the containers that logically belong together. Like a webapp with database and frontend container. It is the combination of technologies like databases, front-end, back-end, etc used to run an application.
<aside> 💡
Food Analogy
Dockerfile is recipe, the image is the batter that contains ingredients and the container is the cake. Stack is the kitchen setup.
OOP Analogy
Docker image is a class, container is an object (instance) of the class.
Code Analogy
The Dockerfile is source code, the image is an executable and the container is a process.
</aside>
Start a Docker application and all its services located in the yaml file
# in detached mode (background)
docker compose up -d
End a docker compose application and its services
docker-compose down --volumes --remove-orphans
List all the containers including the stopped ones
docker ps -a
Run a container from image
docker run --rm project:latest
To start an existing container which is stopped
docker start <container-name/ID>
Login to the interactive shell (bash) of a container
docker exec -it <container-name/ID> bash
docker run --rm -it project:latest bash
To stop a running container