What is Docker Image (original) (raw)

Last Updated : 8 Apr, 2026

A Docker Image is a lightweight, standalone and executable software package that includes everything needed to run an application: the code, a runtime, system tools, libraries and settings.

Dockerfile

If a Dockerfile is the **recipe, then a Docker Image is the perfectly packaged, ready-to-use meal created from that recipe. This package is completely portable, meaning it will run the exact same way on your laptop, a teammate's computer, or a production server.

Components of a Docker Image

A Docker image isn't one large, monolithic file. It's cleverly constructed from a series of layers and stored in a registry.

Layers

An image is composed of a stack of read-only layers. Each instruction in a Dockerfile (like FROM, COPY, RUN) creates a new layer on top of the previous one.

Base Image

This is the foundational layer of your image, specified by the FROM instruction in a Dockerfile. It can be a minimal operating system like alpine, a programming language runtime like python:3.9-slim, or an application like nginx.

Docker Registries

A Docker Registry is a storage and distribution system for Docker images. It's a library where you can pull official images, find images shared by the community, and push your own.

The following are the some of the commands that are used for Docker Images:

Command Description
docker image build This command is used for building an image from the Dockerfile
docker image history It is used for knowing the history of the docker image
docker image inspect It is used for displaying the detailed information on one or more images
docker image prune It used for removing unused images that are not associated with any containers
docker image save This command helps in saving the docker images into a tar archived files
docker image tag It helps in crating a tag to the target image that refers to the source image.

Docker Image Prune

Docker image prune is a command used in the docker host to remove the images that are not used or Docker image prune command is used to remove the unused docker images.

docker image prune

docker_image_prune

All the unused images are also know as dangling images which re not associated with any containers

Docker Image Build

The Following is the command which is used to build the docker image.

docker build -t your_image_name:tag -f path/to/Dockerfile

Docker Image Tag

Docker tags are labels for container images, used to differentiate versions and variants of an image during development and deployment. Docker tags will help you identify the various versions of docker images and help distinguish between them. Docker image will help us to build continuous deployment very quickly

Docker Image Vs Docker Container

The following are the difference between Docker Image and Docker Container:

Docker image Docker container
The Docker image is the Docker container's source code. The Docker container is the running instance of the Docker image.
Dockerfile is a prerequisite to Docker Image. Docker Image is a pre-requisite to Docker Container.
Docker images can be shared between users with the help of the Docker Registry. Docker containers can't 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.

**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 :

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 :

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.

How to Build Docker Python Images

This is the complete process of building and running a Python application inside a Docker container

**Step 1: Create A Dockerfile

Use the official Python image as a base

FROM python:3.9-slim

Set the working directory in the container

WORKDIR /app

Copy the current directory contents into the container at /app

COPY . /app

Install any needed dependencies specified in requirements.txt

RUN pip install --no-cache-dir -r requirements.txt

Make port 80 available to the world outside this container

EXPOSE 80

Define environment variable

ENV NAME World

Run app.py when the container launches

CMD ["python", "app.py"]

Dockerfile

Dockerfile

**Step 2: Create requirements.txt and app.py Files

Filename: requirements.txt

Flask==2.1.0 Werkzeug==2.1.2 # Ensure this is compatible with Flask 2.1.0

requirementstxt

requirements.txt

Filename: app.py

from flask import Flask

app = Flask(name)

@app.route('/') def hello_world(): return 'Hello, World!'

if name == 'main': app.run(debug=True, host='0.0.0.0', port=80)

app_py

app.py

**Step 3: Build a Docker Image

docker image build -t mypython-app:v1 .

docker_image_build_t_mypython-app-v1

Build a Docker Image

**Step 4: Verify the Docker Image

docker images

docker_images

Verify the Docker Image

**Step 5: Run a Python based Docker Container

docker run -dit -p 80:80 --name mycontainer1 mypython-app:v1

Run_a_Python_based_Docker_Container

Run a Python based Docker Container

Step 6: Access the Docker Container

HelloWorld

Access the Docker Container

**Docker Image commands

The following are the some of the Docker Image Commands that are widely used:

**List Docker Images

docker images

**Example

$ 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 Docker Image From a Registry

docker image pull

**Example

$ docker pull alpine:3.11

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

Docker Images Prune

docker image prune

Docker Images Filter

docker image ls -f "reference=mypython-app"

**Remove an Image from Docker

docker rmi

**Example

$ docker rmi

Untagged: Deleted: sha256:

**Searching for a specific image on Docker Hub

docker search ubuntu

**Example

$ 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]

ansible/ubuntu14.04-ansible

The following are the some of the troubleshooting common issues related to docker images: