In the previous part, we learned about Docker containers. Each Docker container is created from a Docker image. Docker images cannot be changed. And they are only used to create containers (for simplicity, you can consider images as installation files and containers as installed programs; the installation file of a program cannot be changed, but if we install the program, the installed program Changes can be made in it. So, we summarize the work so far in the below pictures :)
- The images are read-only. As I mentioned, you can't change the image, but you can create a new image based on the original image.
- The images are layered. If you create a new image based on the original image, a new layer will add to the previous layers. Pay attention that all images are crated from another image (name based image) for example the
nginx imageis created fromubuntu image. The previous image doesn't remove, and the new layer will be added to last ones. Interesting to know all the docker images technically created fromscratchimage; It means all the images has the same layer as their first layer. - As you can see in the right picture, we can create a container from an image, and also we can create an image from a container :)) I put the related commands in the below section, but we will learn them in the future and in the command section.
You can use the below command to run a container from an image.
docker run --name [CONTAINER_NAME] IMAGE_NAME [COMMAND]
For creating an image from the running container, you can use the below command.
docker commit [OPTIONS] CONTAINER_NAME NEW_IMAGE_NAME
-
Docker images could be creating from Dockerfile that you will learn it soon.
-
Docker images are stored in a Docker registry (that we will learn it in the next lessons), either locally on your machine (they store on your machine when you pull them) or in a remote repository like Docker Hub.
-
You can see the images on your local machine using
docker imagesordocker image lscommands. -
You can pull images from Docker registry using
docker pull IMAGE_NAMEcommand.
-
Also, you can push the images from your local machine to registry (if you have push access) using
docker push IMAGE_NAMEcommand. -
If you want to remove the image from your local machine, you can use
docker rmi IMAGE_NAME...ordocker image rm IMAGE_NAME...commands. -
Finally, you can tag on your images using
docker tagcommand.
Please read about all of the commands from command section


