DEV Community

Cover image for Docker Explained: Containers, Images & Why They Changed Everything
Md Mohiuddin
Md Mohiuddin

Posted on

Docker Explained: Containers, Images & Why They Changed Everything

Over the last decade, Docker has transformed how software is built, shipped, and deployed. Today, almost every modern platform, cloud environment, CI/CD pipeline, and Kubernetes cluster relies on containers in some way.

If you've ever heard developers say:

"It works on my machine."

Docker was built to solve exactly that problem.

In this article, we'll explore:

  • What containers actually are
  • How Docker works under the hood
  • Images vs Containers
  • Why containers are lighter than virtual machines
  • Docker architecture explained
  • Running your first Docker containers

Let's dive in.


Why Docker Matters

Before Docker became mainstream, deploying applications was often frustrating.

A developer might have:

  • Python 3.10 installed locally
  • Specific system libraries
  • Certain environment variables
  • Particular package versions

Everything worked perfectly on their laptop.

Then the same application would fail in staging or production because the environment was slightly different.

This became known as:

"Works on my machine."

Docker solves this problem by packaging the application and everything it needs to run into a single portable unit.

No matter where that container runs, the environment remains consistent.


What Is a Container?

A container is:

A portable package that contains application code, dependencies, libraries, runtime components, and configuration required to run an application consistently across environments.

Think of it like a shipping container.

The contents inside don't matter.

As long as the container exists, it can be moved anywhere and still contain everything required.

Software containers work the same way.

A container can run:

  • On a developer laptop
  • In a test environment
  • On a cloud server
  • Inside Kubernetes

without modification.


The Linux Magic Behind Containers

Docker didn't invent containers from scratch.

It built upon powerful Linux kernel features.

Namespaces

Namespaces create isolation.

Each container gets its own view of:

  • Processes
  • Networking
  • Filesystems
  • Users

From inside the container, it feels like its own machine.

Even though multiple containers share the same host.

Control Groups (cgroups)

Control Groups (cgroups) manage resources.

They allow Docker to control:

  • CPU usage
  • Memory usage
  • Disk I/O
  • Resource limits

This prevents one container from consuming all available resources.

Together, namespaces and cgroups create the foundation of containerization.


Docker Architecture Explained

Many beginners think the Docker CLI does all the work.

It doesn't.

Docker uses a client-server architecture.

Docker Client (CLI)
        |
        | API Request
        v
Docker Daemon (dockerd)
        |
        |-- Images
        |-- Containers
        |
        |-- Pull/Push
        v
     Docker Hub
Enter fullscreen mode Exit fullscreen mode

Let's break down each component.

Docker Client

The Docker Client is the command you type.

docker run nginx
Enter fullscreen mode Exit fullscreen mode

The client simply sends instructions to the Docker daemon.

It does not run containers directly.

Docker Daemon (dockerd)

The Docker daemon is the engine behind Docker.

It handles:

  • Building images
  • Running containers
  • Creating networks
  • Managing storage volumes
  • Communicating with registries

Whenever you execute a Docker command, the daemon performs the actual work.

Docker Images

A Docker image is:

A read-only blueprint used to create containers.

Images contain:

  • Operating system layers
  • Runtime dependencies
  • Application code
  • Startup configuration

An image is not running.

It's simply a template.

Think of it like a class in object-oriented programming.

Docker Containers

A container is:

A running instance of an image.

Using the same image, you can launch multiple containers.

nginx image
   |
   |--> Container A
   |--> Container B
   |--> Container C
Enter fullscreen mode Exit fullscreen mode

Each container runs independently while sharing the same underlying image.

Think of a container as an object created from a class.


Docker Hub and Image Registries

Docker images need a place to live.

That's where registries come in.

The most popular registry is Docker Hub.

Common commands include:

docker pull nginx
Enter fullscreen mode Exit fullscreen mode

Downloads an image.

docker push my-image
Enter fullscreen mode Exit fullscreen mode

Uploads an image.

You can think of Docker Hub as GitHub for Docker images.


Understanding Docker Image Layers

One of Docker's most powerful features is layered images.

Each image consists of multiple read-only layers.

Writable Container Layer
------------------------
COPY app.py .
------------------------
RUN pip install ...
------------------------
FROM python:3.12-slim
Enter fullscreen mode Exit fullscreen mode

Each Dockerfile instruction creates a new layer.

When a container starts, Docker adds a writable layer on top.

All runtime changes happen there.

The original image remains unchanged.


Why Layers Matter

Faster Builds

Docker caches layers.

If only application code changes, Docker reuses dependency layers.

This dramatically speeds up rebuilds.

Shared Storage

Suppose two images both use:

python:3.12-slim
Enter fullscreen mode Exit fullscreen mode

Docker stores that base layer only once.

This saves disk space.

Disposable Containers

Containers can be destroyed and recreated instantly.

Because images never change, every new container starts from a clean state.

This consistency is one of Docker's biggest strengths.


Containers vs Virtual Machines

Many newcomers confuse containers with virtual machines.

They solve similar problems differently.

Virtual Machine Docker Container
Includes a full guest OS Shares host kernel
Larger in size Much smaller
Slower startup Fast startup
Strong isolation Lightweight isolation
Consumes more resources More efficient

Virtual Machine

Application
Guest OS
Hypervisor
Host OS
Hardware
Enter fullscreen mode Exit fullscreen mode

Docker Container

Application
Libraries
Docker Engine
Host OS Kernel
Hardware
Enter fullscreen mode Exit fullscreen mode

Containers share the host kernel.

This is why they start in seconds instead of minutes.


Installing Docker

Windows and macOS

Install Docker Desktop.

It includes:

  • Docker CLI
  • Docker Engine
  • Docker Desktop UI
  • Lightweight Linux VM

Linux

Install Docker Engine directly.

Linux already provides the kernel Docker needs.

No additional VM layer is required.

Follow the installation guide for your distribution.


Your First Docker Container

The classic first command is:

docker run hello-world
Enter fullscreen mode Exit fullscreen mode

A lot happens behind the scenes.

  1. Docker checks for the image locally.
  2. If it doesn't exist, Docker downloads it.
  3. Docker creates a container.
  4. The container runs.
  5. The program exits successfully.

Congratulations.

You just ran your first container.


Running a Real Application

Let's run Nginx.

docker run -d -p 8080:80 --name my-nginx nginx
Enter fullscreen mode Exit fullscreen mode

-d

Runs the container in detached mode.

-p 8080:80

Maps ports.

Host Port      Container Port
8080     -->        80
Enter fullscreen mode Exit fullscreen mode

Traffic reaching your machine on port 8080 gets forwarded to Nginx running inside the container.

--name my-nginx

Assigns a custom container name.

nginx

Specifies the image to run.

If it doesn't exist locally, Docker downloads it automatically.


Managing Containers

docker ps
docker ps -a
docker logs my-nginx
docker stop my-nginx
docker start my-nginx
docker rm my-nginx
Enter fullscreen mode Exit fullscreen mode

Then open:

http://localhost:8080
Enter fullscreen mode Exit fullscreen mode

You should see the Nginx welcome page.


Why Docker Won

Traditional Installation

sudo apt update
sudo apt install nginx
Enter fullscreen mode Exit fullscreen mode

Requirements:

  • Linux server
  • Package management
  • System configuration

Docker Installation

docker run -d -p 8080:80 nginx
Enter fullscreen mode Exit fullscreen mode

Requirements:

  • Docker installed

Cleanup:

docker rm my-nginx
Enter fullscreen mode Exit fullscreen mode

Done.

No leftover configuration files.

No package cleanup.

No dependency conflicts.


The Bigger Picture

Docker didn't become popular because it was trendy.

It became popular because it solved real engineering problems:

  • Consistent environments
  • Faster deployments
  • Better resource utilization
  • Easier scaling
  • Simpler application packaging

Today Docker sits at the center of modern DevOps.

  • CI/CD pipelines build Docker images.
  • Cloud platforms deploy Docker containers.
  • Kubernetes orchestrates containers at scale.

Learning Docker isn't just learning another tool.

It's learning the foundation of modern software delivery.


Final Thoughts

Docker changed how software is shipped.

By packaging applications together with their dependencies, containers eliminate environment inconsistencies and make deployments predictable.

As you continue your DevOps journey, you'll discover that Docker is not the destination—it's the foundation.

Everything from CI/CD pipelines to Kubernetes builds upon the concepts you've learned here.

Learn Docker deeply. It will pay dividends throughout your entire DevOps career.

Top comments (0)