Table of contents
No headings in the article.
Docker is all about containers, containers are virtualized environments where your applications run in isolation. An image is an immutable file and is nothing but a snapshot of the container at a given time. To understand the relation between the images and containers, let's take the metaphor of think of images as a class and containers as objects of the class, a runtime object.
Images are stored in the registry, the registry could be private or public. Because images can become quite large, images are designed to be composed of layers of other images, this way the size of the image would be minimal, and sharing the images over the network would be quick and fast.
To download the image:
docker image pull <image_name>
To list all the downloaded images:
docker images
or
docker image ls
Containers are the running instance of images, if the docker image is a blueprint of a house then the docker container is the house by keeping the docker image as reference. You can create, start, stop, move or delete a container, you can connect a container to one or more networks, let containers talk to each other, attach storage to it, or even create a new image based on its current state.
To make a container from a downloaded image
docker container run -d -p <host_port>:<container_port> --name <container_name> <image_name>
To check container
docker container ls
In the below example, it's creating a container from downloaded Nginx image
The default page of the Nginx on localhost
So we pull images from the registry or build from a Dockerfile (Dockerfile is a text file having instructions to create an image), which gives an immutable Docker image, and we run the image to get a mutable container.