DCubes
Docker module

Lesson 2

Images, containers, and Compose

The mental model — image, container, Dockerfile, and Compose file — before you type docker run.

beginner25 minRun on your machine

What you will be able to do

  • Distinguish an image from a container
  • Place Dockerfile and Compose on that picture
  • List the images already on your machine

Why this matters for DE and AI

People say “the Postgres Docker” and mean four different files. Jobs fail because someone edited the running container and never rebuilt the image, or because Compose started the job before the database was ready. This lesson names the pieces so later commands have somewhere to sit.

Concepts

Image — a read-only snapshot: a Linux filesystem plus metadata (default command, exposed ports). postgres:16-alpine is an image name plus tag. You pull it once; many containers can use it.

Container — one running (or stopped) instance of an image. It has a writable layer on top of the image. Delete the container and that layer is gone — unless you put data on a volume.

Dockerfile — a text recipe that builds an image: start from this base, copy these files, run these installs, set this command.

Compose file — YAML that names services (containers), networks, and volumes so a stack is one docker compose up, not twelve flags.

Dockerfile  --build-->  image  --run-->  container
                               \
Compose.yaml  --up-->  several containers + volumes + network

Analogy that is good enough

Kitchen Docker
Recipe Dockerfile
Packaged meal in the freezer Image
A plate you actually eat Container
A dinner plan for several dishes Compose file

You do not store leftovers on the plate and call it the recipe. Warehouse data belongs on a volume (or in a real database), not in the container’s writable layer.

Engine vs client

docker on your prompt is the client. It talks to the engine (Desktop, or dockerd on Linux). The engine pulls images, starts processes, and mounts files. If the engine is down, the client only complains.

What Compose is not

Compose is not Kubernetes. It is a file for this machine (or one VM): services, ports, volumes. Perfect for local data stacks. Orchestrating a cluster is a later career problem.

Practice on your machine

cd ~/dcubes/docker-lab
docker images

What you should see: at least hello-world from Getting Started. Columns are repository, tag, image ID, created, size. Empty is fine if you pruned already — you will pull again.

Ask the client for a one-line engine check:

docker info --format '{{.ServerVersion}}'

A version string means the engine answered. An error means start Desktop / the service.

List containers — running and stopped:

docker ps -a

After docker run --rm hello-world, that container is already gone (--rm). You may see nothing, or leftover rows from experiments. Either is OK.

Write the four words into a note you will keep in the lab:

cat > ~/dcubes/docker-lab/vocab.txt << 'EOF'
image      = snapshot (postgres:16-alpine)
container  = one running copy
Dockerfile = recipe that builds an image
Compose    = file that starts a stack
EOF
cat ~/dcubes/docker-lab/vocab.txt

Common mistakes

  • Calling the image a container. docker images vs docker ps. Different lists.
  • Saving data “in the container.” Next time you rm it, the data goes with it. Volumes come in lesson 8.
  • Editing a running container as if it were the Dockerfile. exec is for debugging, not for shipping.

Next

Run a containerdocker run, --rm, and a shell inside Alpine.