# devops / docker / core-concepts

Demystifying Images & Containers

To master Docker, you must understand its two fundamental building blocks: the static blueprints that define your application, and the dynamic, running environments they spawn.

Architecture Analogyβœ“
BlueprintDocker Image (Read-Only)
ConstructDocker Container (Running)
1
Image
∞
Containers
# images

πŸ“¦ Docker Images

A Docker image is like a blueprint. It contains absolutely everything needed to run an application without relying on the host system's configuration.

immutable

Read-Only & Layered

Images are completely read-only and built in stacked layers. This layered approach makes them fast to pull, incredibly efficient to store, and highly cacheable.

self-contained

What's Inside?

An image packs OS libraries (like Debian/Alpine), your specific runtime (Java, Python, PHP), your application code, and your environment configurations.

REAL LIFE ANALOGY

Think of an image like a cake recipe 🍰. You don’t eat the recipe β€” you use it to bake the cake.

# containers

πŸƒ Docker Containers

Container Lifecycle

  • start

    Spawns the container, attaching a read-write layer over the image.

  • stop

    Gracefully halts the running processes inside the container.

  • restart

    Stops and immediately starts the container back up.

  • delete

    Destroys the container and its temporary read-write data layer.

A container is a running instance of an image. When you start an image, Docker creates a container and adds a writable layer on top, bringing the application to life.

REAL LIFE ANALOGY

Imagine a mobile app installer. The installer file is the Docker Image. The installed and actively running app on your phone is the Docker Container. You can install the same app many times (multiple containers) from one file.

# commands

Essential CLI Operations

Understanding the difference between create, start, and run is crucial. run is simply a combination of create (making the container) followed immediately by start (executing it).

terminal
# Image Commands
$ docker image ls β†’ List all images
$ docker pull ubuntu β†’ Download an image from Hub
$ docker history ubuntu β†’ View build layers
$ docker rmi ubuntu β†’ Remove an image
 
# Container Run Commands
$ docker create ubuntu β†’ Creates, but does NOT start
$ docker start <id> β†’ Starts a created container
$ docker run -d nginx β†’ Create + Start in background
 
# Container Management
$ docker ps β†’ List running containers
$ docker ps -a β†’ List all (running + stopped)
$ docker logs <id> β†’ View container logs
$ docker exec -it <id> /bin/bash β†’ Open interactive shell
$ docker stop <id> β†’ Stop a container
$ docker rm <id> β†’ Remove a container
# summary

The Key Differences

Attribute Docker Image πŸ“¦ Docker Container πŸƒ
State Static, read-only Running, read-write layer added
Purpose Blueprint / Template Active Execution Environment
Real-Life Analogy Cake Recipe / App Installer File Baked Cake / Installed App running
Relationship You need 1 Image... ...to spin up N Containers