Docker images vs containers


Docker is a platform that makes it easier to create, deploy, and use an application using containers. A container contains an application with all parts of it needed such as libraries and other dependencies, and ships it as one package.

Instead of using dedicated resources like virtual machines, docker shares kernel, and other resources of the host system. When you learn docker it has two different concepts i.e. docker images and docker containers.

In this article, we will discuss docker images and containers you will also see differences and similarities between these two.

You can follow how to install docker on Ubuntu if you want to install it in Linux.

Docker images

Docker image is an immutable file that is essentially a snapshot of a container. Images are created with build command, and they produce a container when started with the run command. Docker pulls these images from the Docker Hub or from a local registry.

Docker images consist of multiple layers stacked to one another. The layers may differ from each other but each of them originates from the previous one. These layers essentially are read-only files to which the container layer will be added when you start a virtual environment.

Every time you change the initial state of an image and save the existing state you create a new image with an additional layer on top of the previous image. In this way, you can create an unlimited number of docker images.

Working with docker images

There are certain commands that you can use to work with docker images. Before you execute any docker command make sure you have docker installed on your system.

You can pull a docker image by using the given command.

docker pull ubuntu

This will download the docker image of Ubuntu.

To see the list of downloaded images on your system use –

docker images

This will display output like given in the image.

By using the docker history command you can see all the layers of a docker image.

Docker containers

Before we come to docker containers first understand what is containerization.

Containerization is a process that encapsulates an application in a container with its own operating environment. It is a kind of lightweight alternative to full machine virtualization. The benefit of using the containers is that you can run the applications on any physical machine without worrying about dependencies.

A docker container is an instance of a docker image. This provides a virtualized runtime environment to isolate an application from the underlying system.

Docker defines certain states for a container this include createdrestartingrunningremovingpausedexited, and dead. As we discussed earlier docker images are created using build command, an image produce a container when started with the run command.

Working with docker containers

Docker provides some commands to work with docker containers. Some of them are given below.

After downloading a docker image use the given command to start it as a container –

docker run -it ubuntu

This will start the Ubuntu container in your terminal.

You can see the list of all running containers by using –

docker ps

If you want more to know about docker containers you can see how to run a docker container in Linux.

Docker images vs containers

In the above two sections, we have explained what are docker images and containers. Now you should already have some understanding of how these two are related to each other. Docker images can exist without the container, but you need an image to start a container. Images describe the applications whereas containers are an instance of these images.

Conclusion

I hope you understand the differences between docker images and containers. Now if you have a query then write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.