When using Docker, we start with a base image. We boot it up, create changes and those changes are saved in layers forming another image.
So eventually I have an image for my PostgreSQL instance and an image for my web application, changes to which keep on being persisted.
So the question is: What is a container?
Image is an equivalent to a class definition in OOP and layers are different methods and properties of that class.
Container is the actual instantiation of the image just like how an object is an instantiation or an instance of a class.
An instance of an image is called a container. 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.
You can see all your images with
docker images
whereas you can see your running containers withdocker ps
(and you can see all containers withdocker ps -a
).So a running instance of an image is a container.
In easy words.
Images -
Containers -
Other important terms to notice:
Docker daemon -
Docker client -
Docker Store -
A picture is worth a thousand words.
(For deeper understanding please read this.)
Summary:
docker run image_name:tag_name
) => Gives a running Image i.e. container (editable)As in the programming aspect,
Image is a source code.
When source code is compiled and build, it is called as application.
Simillar to that "when instance is created for the image", it is called as "Container"
Dockerfile is like your bash script that produce a tarball (Docker image).
Docker containers is like extracted version of the tarball. You can have as many copies as you like in different folders (the containers)
The core concept of docker is to make it easy to create "machines" which in this case can be considered containers. The container aids in reusability, allowing you to create and drop containers with ease.
Images depict the state of a container at every point in time. So the basic workflow is: