Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

What is Docker Images?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Pre-requisite: Introduction to Docker

Docker Image is an executable package of software that includes everything needed to run an application. This image informs how a container should instantiate, determining which software components will run and how. Docker Container is a virtual environment that bundles application code with all the dependencies required to run the application. The application runs quickly and reliably from one computing environment to another.

Docker Flow


Uses of Docker Images

  1. We can easily and effectively run the containers with the aid of docker images.
  2. All the code, configuration settings, environmental variables, libraries, and runtime are included in a Docker image.
  3. Docker images are platform-independent. 
  4. Layers are the building blocks of an image. 
  5. WithWhen using the build command, the user has the option of completely starting from scratch or using an existing image for the first layer.

Difference between Docker Image and Docker Container

Docker imageDocker container 
The Docker image is the Docker container’s source code.The Docker container is the instance of the Docker image.
Dockerfile is a prerequisite to Docker Image.Docker Image is a pre-requisite to Docker Image.
Docker images can be shared between users with the help of the Docker Registry. Docker Containers cant be shared between the users.
To make changes in the docker image we need to make changes in Dockerfile.We can directly interact with the container and can make the changes required.

Structure Of Docker Image 

The layers of software that make up a Docker image make it easier to configure the dependencies needed to execute the container. 

  • Base Image: The basic image will be the starting point for the majority of Dockerfiles, and it can be made from scratch.
  • Parent Image: The parent image is the image that our image is based on. We can refer to the parent image in the Dockerfile using the FROM command, and each declaration after that affects the parent image.
  • Layers: Docker images have numerous layers. To create a sequence of intermediary images, each layer is created on top of the one before it. 
  • Docker Registry: Refer to this page on the Docker Registry for further information.

How To Create A Docker Image And Run It As Container?

Follow the below steps to create a Docker Image and run a Container:

Step 1: Create a Dockerfile.

Step 2: Run the following command in the terminal and it will create a docker image of the application and download all the necessary dependencies needed for the application to run successfully.

docker build -t <name>:<tag> 

This will start building the image.

Step 3:  We have successfully created a Dockerfile and a respective Docker image for the same.

Step 4: Run the following command in the terminal and it will create a running container with all the needed dependencies and start the application.

docker run -p 9000:80 <image-name>:<tag> 

The 9000 is the port we want to access our application on. 80 is the port the container is exposing for the host to access.

 Docker Image commands

List images

docker ls


$ docker ls

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              0d9c6c5575f5        4 days ago          126MB
ubuntu              18.04               47b199b0cb85        2 weeks ago         64.2MB

Pull an image from a registry

docker image pull <image-name>


$ docker pull alpine:3.11

3.11: Pulling from library/alpine
Digest: sha256:9f11a34ef1c67e073069f13b09fb76dc8f1a16f7067eebafc68a5049bb0a072f
Status: Downloaded newer image for alpine:3.11

 Remove an Image from Docker

docker rmi <id-of-image>


$ docker rmi <image_id>

Untagged: <image_id>
Deleted: sha256:<image_id>

 Searching for a specific image on Docker Hub

docker search ubuntu


$ docker search ubuntu

NAME                             DESCRIPTION                                                          STARS                 OFFICIAL                          AUTOMATED

ubuntu                           Ubuntu is a Debian-based Linux operating s…                4458                    [OK]               

ubuntu-upstart              Upstart is an event-based replacement for …                  62                         [OK]               

tutum/ubuntu                 Simple Ubuntu docker images with ssh access             49                          [OK]               


My Personal Notes arrow_drop_up
Last Updated : 25 Apr, 2023
Like Article
Save Article
Similar Reads
Related Tutorials