Skip to main content

Infrastructure and deployment

What is Docker?

Definition

Docker is a toolset for building, sharing and running containers, packaging an application with its dependencies into an image that runs the same way anywhere.

Docker in more detail

Docker did not invent containers — the kernel features predate it by years — but it made them usable by giving the world a single file format, a command-line workflow and a public registry. You write a Dockerfile describing how to assemble the image, run docker build to produce it, docker push to share it and docker run to start it. The reproducibility that follows is what killed 'works on my machine' as an acceptable answer.

An image is built in layers, one per instruction, and each is cached. Ordering instructions so the slow, rarely-changing steps come first — copy the dependency manifest and install before copying the source — turns a two-minute rebuild into two seconds. Multi-stage builds go further: compile in a fat toolchain stage, then copy only the resulting binary into a slim runtime image, so the shipped artifact carries no compilers or build caches.

Docker itself is now one implementation among several. Images and runtimes are standardised by the OCI, so Podman, containerd, Buildah, BuildKit and Kubernetes all consume the same artifacts, and Kubernetes stopped using Docker as its runtime in 2022 without any image needing to change. Locally, Docker Compose remains the shortest path to running an application together with its database and cache from one file.

Docker example

# Multi-stage build: build fat, ship slim
FROM node:22 AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci                    # cached until the manifest changes
COPY . .
RUN npm run build

FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
USER node                     # do not run as root
EXPOSE 3000
CMD ["node", "dist/server.js"]

$ docker build -t myapp:1.4 .
$ docker run -p 3000:3000 --env-file .env myapp:1.4
$ docker compose up -d        # app + postgres + redis together

Docker — common questions

Is Docker the same as a container?
No. A container is the isolated process; Docker is one popular set of tools for building and running them. Podman, containerd and others run the same OCI images without Docker being installed at all.
What is the difference between CMD and ENTRYPOINT?
ENTRYPOINT sets the executable that always runs; CMD supplies default arguments that a docker run argument can replace. Using ENTRYPOINT for the binary and CMD for its flags gives a container that behaves like the command it wraps.
Why is my Docker image so large?
Usually because build tooling, caches and source files ended up in the final layer, or the base image is a full distribution. Multi-stage builds, a slim or distroless base, a .dockerignore file and combining RUN steps that clean up after themselves fix most of it.

Keep reading

This page explains what Docker means. For the syntax itself, the Docker cheat sheet is a full reference of real commands and examples. Every other definition is in the A-Z glossary.

Browse the A-Z glossary