Skip to content
Independent notebook · software, testing, and open source No ads · no sponsored posts · no affiliate links
Soham Parekh software notebook

Coding note / Containers

Docker

A short map of Docker: images, containers, services, and the commands that make the model click.

Shelf Containers

Format Reference

All notes

Docker packages an application and the environment it needs, so the same bundle can run on a laptop, a test machine, or a server. The vocabulary is small, but the words are easy to mix up. This note keeps the model and the commands in one place.

The model

  • An image is a packaged filesystem and configuration for an application. It includes the code, runtime, libraries, and environment settings the application needs.
  • A container is what you get when an image starts running. It is isolated from the host and from other containers, but it shares the host kernel.
  • A Dockerfile is the recipe used to build an image.
  • A service describes how containers should run in production, including how many instances and how they are connected.
  • A stack is a group of services that work together.

The hierarchy

  1. Stack at the top, describing the whole application.
  2. Services in the middle, describing each moving part.
  3. Containers at the bottom, doing the actual work.

If you remember one thing, remember that the image is the package and the container is the running process. Everything else is a way of organising those two ideas at a larger scale.

Commands I reach for

terminal
docker version
docker info
docker images
docker ps
docker pull python
docker run python
docker stop CONTAINER
docker compose up
  • docker version prints the client and server versions.
  • docker info shows more detail about the installation.
  • docker images lists the images on the machine.
  • docker ps lists running containers.
  • docker pull downloads an image from a registry.
  • docker run starts a container from an image.
  • docker stop stops a running container.
  • docker compose up starts the services in a Compose file.

Compose in one paragraph

Compose lets you describe several services in one file, usually called compose.yaml. Each service names an image or a build context, and the file records the ports, volumes, and environment variables that connect them. One command starts the group, which is why Compose is a good fit for local development.

A note on GPU containers

Running a container with access to a GPU requires more than the Docker engine. The host needs a compatible driver, and the container runtime needs to be configured to expose the device. The NVIDIA Container Toolkit documents that setup. It is a host configuration problem, not an application problem, so solve it before you debug the application image.

Cleanup

Images and stopped containers accumulate. List them before removing anything, and be specific about what you delete. A broad cleanup command is convenient until it removes the image you needed for the next experiment.

Field note

An image is a recipe. A container is the meal. A service is the restaurant telling you how many meals to prepare.

Reference shelf

Official documentation and further reading for this note.