Skip to content

Docker Image vs Docker Container โ€“ Differences with Examples

โ† Back to Docker


Docker images and Docker containers are core concepts every Docker beginner must understand.

In simple terms, a Docker image is a read-only template, while a Docker container is a running instance created from that image.

In this guide, youโ€™ll learn: - What a Docker image is - What a Docker container is - Key differences between images and containers - Real Docker examples using Ubuntu


What is a Docker Image?

A Docker image is a lightweight, immutable, read-only template that contains everything required to run an application: - Application code - Runtime - Libraries - Dependencies

Docker images are used as blueprints to create containers.

All Docker images are stored in a Docker registry, most commonly Docker Hub.

๐Ÿ‘‰ Docker Hub: https://hub.docker.com


What is a Docker Container?

A Docker container is a running instance of a Docker image.

When a container is created: - The image stays unchanged (read-only) - A writable layer is added on top - The application starts running

If the container stops, the image remains intact.


Docker Image vs Docker Container โ€“ Comparison Table

Feature Docker Image Docker Container
Nature Static Dynamic
State Read-only Read-write
Purpose Blueprint Running application
Created using Dockerfile docker run
Stored in Docker registry Host system
Lifecycle Does not run Can start, stop, restart

ISO Image vs Docker Image (Easy Analogy)

An ISO image is a static installation file. Applications run only after the operating system is installed and started.

Similarly: - A Docker image is a static package - A Docker container runs applications from that image

ISO vs Docker Image


Pulling Docker Images from Docker Hub

Check existing images on the server:

docker image ls

Pull the Ubuntu image:

docker pull ubuntu

By default, Docker pulls the latest tag.


Pulling a Specific Image Tag

Docker images follow this format:

IMAGE_NAME:TAG

Example:

docker pull ubuntu:23.10

Verify images:

docker images

Creating a Docker Container from an Image

Create a container using the Ubuntu image:

docker run -it ubuntu:23.10 bash

Inside the container:

pwd
ls
id
cat /etc/os-release

This confirms that the container is running Ubuntu 23.10 using the image.


Image and Container Relationship

  • One image โžœ multiple containers
  • Containers can be stopped or removed
  • Images remain unchanged

FAQs

Is a Docker container an image?

No. A Docker container is created from an image and represents a running process.

Can one Docker image create multiple containers?

Yes. A single image can be used to create multiple containers.

What happens when a container stops?

The container stops running, but the image remains unchanged.


Next Steps

๐Ÿ‘‰ What is Docker?
๐Ÿ‘‰ How to Install Docker on Linux


๐Ÿง  Quick Quiz โ€” Docker Image vs Container

#

Which of the following statements is true?


๐Ÿ“ Want More Practice?

๐Ÿ‘‰ Test your knowledge โ€“ Take the Docker Basics Quiz


๐Ÿ“ฌ DevopsPilot Weekly โ€” Learn DevOps, Cloud & Gen AI the simple way.
๐Ÿ‘‰ Subscribe here