Stop by Stop

DevOps line

Docker

Docker packs your app and all it needs into a sealed meal kit, so any kitchen can cook it the same way.

Words to know

Stops explain each step. The film plays the whole ride.

Explain it
Route
YouWrites the recipeRecipe cardSteps to followMeal kitSealed, stacked traysShop shelfKits wait hereCooked mealMade from the kitLeftovers boxKept outside the pot
  • A step you start
  • Quietly piling up
  • Made or kept
  • Something went wrong
Stop 1 of 9

You write the recipe

You write a recipe card for your app: start from a ready-made base, add the tools it needs, add your code, then say how to start it.

Next stop: The recipe becomes a kit

All stops

The everyday version

Cooking from a meal kit works the same way. Every stop has a twin in the kitchen.

  • Youis the Developer

    Write the recipe card and decide what to cook.

  • The recipe cardis the Dockerfile

    Lists every step in order: what to start from, what to add, and how to begin.

  • The meal kitis the Image

    A sealed box of stacked trays. Once packed it never changes, and it can make many meals.

  • The shop shelfis the Registry

    Keeps finished kits so any kitchen can pick one up.

  • The cooked mealis the Container

    One live copy made from the kit. Wash the pot and it is gone.

  • The leftovers boxis the Volume

    Sits outside the pot, so what is kept in it survives when the pot is washed.

  • Sauce down the drainis data lost with its container

    Without a leftovers box, anything left in the pot is washed away with it. Keep what matters in the box.

Interview questions

Say the short answer first. Go deeper only if they ask.

What is the difference between an image and a container?
Short answer

An image is the read-only template, and a container is a running instance of it.

If they dig deeper

Many containers can run from one image, and each gets its own thin writable layer. Deleting a container deletes that layer, while the image stays unchanged.

Answer that loses points

“A container is a lightweight VM with its own kernel.”

How do image layers and the build cache work?
Short answer

Each instruction adds a layer, and Docker reuses a layer while nothing it depends on has changed.

If they dig deeper

Once one layer changes, every layer after it is rebuilt. Order instructions from least to most often changed: copy requirements.txt and install before copying the source. A cached RUN is not invalidated automatically, so use --no-cache for a fresh install.

Answer that loses points

“COPY . . first, then pip install.”

What is the difference between CMD and ENTRYPOINT?
Short answer

ENTRYPOINT sets the main executable, and CMD supplies its default arguments, or the default command when there is no ENTRYPOINT.

If they dig deeper

Arguments to docker run <image> replace CMD and are appended to an exec-form ENTRYPOINT; --entrypoint overrides it. Prefer exec form, ["uvicorn", "app:app"]: shell form runs under /bin/sh -c, so the app is not PID 1 and never gets the SIGTERM from docker stop.

Answer that loses points

“They are identical.”

Where should data that must survive be kept?
Short answer

In a volume or a bind mount, not in the container’s writable layer.

If they dig deeper

A named volume is managed by Docker and outlives the container; a bind mount maps a host path, which suits development. docker rm never deletes a named volume, and -v only removes anonymous ones. Remove a named volume with docker volume rm.

Answer that loses points

“Data stays in the container forever.”

How do containers differ from virtual machines?
Short answer

Containers share the host’s kernel, while a VM runs a full guest operating system with its own kernel.

If they dig deeper

Docker isolates each container with Linux namespaces, and cgroups can cap its CPU and memory (there are no limits by default). A container starts from an image instead of booting its own operating system, so it carries less overhead.

Answer that loses points

“Docker virtualizes the hardware.”

What does -p 8080:80 do?
Short answer

It publishes container port 80 on host port 8080. The host port comes first.

If they dig deeper

By default the port is published on every host address, so outside clients can reach it, and -p 127.0.0.1:8080:80 limits it to the host itself. EXPOSE only documents a port and does not publish it. Unpublished ports are unreachable from outside the host.

Answer that loses points

“EXPOSE opens the port to the outside.”

How do containers find each other by name?
Short answer

On a user-defined bridge network Docker resolves container names. On the default bridge it does not.

If they dig deeper

Run docker network create net, then start containers with --network net. They reach each other by name or alias. On the default bridge they can only use IP addresses, unless you use --link.

Answer that loses points

“Containers on the default network can call each other by name.”

What is a multi-stage build?
Short answer

A Dockerfile with several FROM stages: build in one, then COPY --from only the result into a small final stage.

If they dig deeper

Compilers and build tools stay in the earlier stage, so the final image is smaller. Name a stage with AS, and build only up to one stage with --target.

Answer that loses points

“One stage with the compiler and every build tool is fine for production.”

Cheat-sheet

Commands you will actually type.

docker build -t myapp:1.0 .

Build an image from the Dockerfile in this folder and tag it.

docker run -d --name api -p 8000:8000 --env-file .env myapp:1.0

Run in the background, name it, publish host port 8000, and read variables from a file.

docker ps -a

List containers, including stopped ones.

docker logs -f api

Follow a container’s log output.

docker exec -it api sh

Open a shell inside a running container.

docker run -v data:/data myapp:1.0

Mount the named volume data at `/data`. Docker creates it if it is missing.

docker network create net

Make a user-defined bridge network, then start containers with `--network net` so they reach each other by name.

docker stop api && docker rm api

Stop the container (SIGTERM first, SIGKILL after a grace period), then remove it.

Sources