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
- Stack at the top, describing the whole application.
- Services in the middle, describing each moving part.
- 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
docker version
docker info
docker images
docker ps
docker pull python
docker run python
docker stop CONTAINER
docker compose up
docker versionprints the client and server versions.docker infoshows more detail about the installation.docker imageslists the images on the machine.docker pslists running containers.docker pulldownloads an image from a registry.docker runstarts a container from an image.docker stopstops a running container.docker compose upstarts 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.
An image is a recipe. A container is the meal. A service is the restaurant telling you how many meals to prepare.