Images, Dockerfiles, volumes, networks, debugging
Practise these as flashcards. One or two lines each; the ones you miss come back first.
Start freeA VM has its own kernel on a hypervisor, takes minutes to boot and is heavier. A container shares the host kernel, isolates processes with namespaces and cgroups, starts in seconds and is much smaller. VMs give stronger isolation; containers are better for packaging and scaling apps.
An image is the read-only template. A container is a running instance of it with a writable layer. One image can run many containers.
Publish the container's port 80 on the host's port 8080. Traffic to host:8080 goes to the container's port 80.
ENTRYPOINT sets the fixed executable. CMD gives default arguments that docker run can override. Together: ENTRYPOINT is the program, CMD is its default flags.
COPY copies files from the build context. ADD also unpacks local tar files and can fetch URLs. Prefer COPY because it's predictable.
docker ps -a for the exit code, docker logs for the output. Common causes: the main process finished (it must run in the foreground), a bad command or config, a missing env var. Exit 137 means it was killed, often out of memory.
Data written inside the container lives in its writable layer, which is deleted with the container. Store it in a named volume or a bind mount instead.
Use a slim or distroless base, use multi-stage builds, combine RUN steps and clean package caches in the same step, and add a .dockerignore so you don't copy junk into the build.
They're on the default bridge network, which has no name resolution. Put them on a user-defined network (docker network create) and they can find each other by container name.
no (default), on-failure (restart on non-zero exit), always, and unless-stopped (always, unless you stopped it by hand).
The process got SIGKILL, most often from the out-of-memory killer. Confirm with docker inspect (State.OOMKilled) and raise the memory limit or fix the app.
Compose runs a multi-container app on one host, good for dev and small setups. Kubernetes runs containers across many nodes with scheduling, self-healing, scaling and rolling updates.