Skip to content
Commitpedia
Log in Join & edit

Docker images, containers and volumes explained

An image is a read-only template, a container is a running copy of it with a thin writable layer, and a volume is storage that outlives the container. Learn how the three fit together and which commands act on each.

Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?

Edit history of Docker images, containers and volumes explained: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
3 min

Docker packages a program together with everything it needs to run, so that it behaves the same on a laptop, a test server and in production. Almost everything you do with Docker touches one of three objects: images, containers and volumes. Once the difference is clear, the command line stops feeling random.

Images: the read-only template

An image is a frozen file system plus some metadata: which command to start, which ports the program listens on, which environment variables it expects. Images are built from a Dockerfile and are made of layers. Each instruction in the Dockerfile adds a layer on top of the previous one, and layers are shared between images, which is why pulling a second image based on the same base is fast.

Images are named like repository:tag, for example nginx:1.27 or postgres:17. If you leave out the tag, Docker assumes latest, which is a moving target and not a good idea on servers. Images live in a registry; Docker Hub is the default, and docker pull downloads from there.

docker pull nginx:1.27
docker image ls
docker image history nginx:1.27
docker image inspect nginx:1.27

Containers: a running copy with a writable layer

A container is what you get when you run an image. Docker takes the image layers, adds one thin writable layer on top, gives the process its own network interface and process list, and starts the command. You can start many containers from the same image and they do not see each other’s changes.

The writable layer belongs to that one container. When the container is removed with docker rm, everything written there is gone. Stopping a container does not delete it; the files stay until you remove it, which is why docker ps -a often shows a long list of exited containers.

docker run -d --name web -p 8080:80 nginx:1.27
docker ps
docker logs web
docker exec -it web sh
docker stop web
docker rm web

-d runs the container in the background, --name gives it a name you can refer to, and -p 8080:80 publishes port 80 inside the container as port 8080 on your machine. Without -p the service is reachable only from other containers.

Volumes: storage that survives the container

Because the writable layer disappears with the container, anything you care about, such as a database’s data directory or uploaded files, must live somewhere else. That is what volumes are for. A volume is a directory managed by Docker, stored on the host, that is mounted into the container at a path you choose. Remove the container, start a new one with the same volume, and the data is still there.

docker volume create pgdata
docker run -d --name db -e POSTGRES_PASSWORD=example -v pgdata:/var/lib/postgresql/data postgres:17
docker volume ls
docker volume inspect pgdata

There is a second kind of mount, the bind mount, which maps a normal host directory into the container, for example -v "$PWD":/app. Bind mounts are handy during development because edits on the host appear in the container immediately. Named volumes are the better choice for data a service owns, because Docker manages their location and permissions.

Careful: docker volume rm and docker volume prune delete data permanently. A volume is only removed by prune when no container references it, but a volume you forgot to attach counts as unused.

How they fit together

  • Image: built once, read-only, shared, versioned by tag. Commands start with docker image or docker build.
  • Container: a process started from an image, with its own writable layer and network. Commands start with docker container, or the short forms docker run, docker ps, docker stop.
  • Volume: persistent storage attached to one or more containers. Commands start with docker volume.
  • Network: the fourth object you meet soon after. Containers on the same user-defined network can reach each other by name. Commands start with docker network.

A good mental model: images are like installation media, containers are like a machine you booted from it, and volumes are like an external disk you plug into that machine.

Official documentation

Did this work for you?

No votes yet. Be the first.

If it did not work, the report form below tells the editors what went wrong.

See also

  • 0055 Docker basics: images, containers and the commands you need An image is a read-only package of an app and its dependencies, and a container is a running instance of it. Learn… Beginner · Explains an idea · Linux, macOS, Windows Article Docker basics 15 Oct 2026
  • 0056 Docker Compose: run a small web app with a database Docker Compose describes several containers, their ports, volumes and environment in one compose.yaml file, then starts them all with docker compose up. Intermediate · Step by step · Linux, macOS, Windows Article Docker basics · Docker Compose 15 Oct 2026
  • 0250 Containerize a Node.js app and run it with PostgreSQL using Docker Compose Package a small Node.js web app in a multi-stage Docker image, then run it next to PostgreSQL with Docker Compose, named volumes,… Intermediate · Guided project · Linux, macOS, Windows Article Docker basics · Docker Compose · PostgreSQL 15 Oct 2026
  • 0268 What is a container? A container is a lightweight box that packs a program with everything it needs so it runs the same on any computer. Beginner · Explains an idea · Any system Article Docker basics 15 Oct 2026
  • 0328 Install Docker Engine on Ubuntu and Debian Set up Docker's official apt repository, install Docker Engine with the Compose and Buildx plugins, run hello-world and let your user run… Beginner · Step by step · Linux Article Docker basics · Packages & updates 15 Oct 2026
  • 0329 Docker CLI cheat sheet The Docker commands you reach for every day, grouped by what they act on: containers, images, volumes, networks, logs and cleanup, with… Beginner · Cheat sheet · Linux, macOS, Windows Article Docker basics 15 Oct 2026

Repos in the wild

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. Dominik +4,181 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?