skip to content

Container Lifecycle

How a container starts, runs and dies: run/start/exec, restart policies, CPU and memory limits, runtime health state, signals and exit codes. Interviewers probe it because graceful shutdown and PID 1 are where deploy-time data loss actually comes from.

part ofDockeroverview, primer and where to startread it →
on this pageshow

questions

page 2 of 2

`docker run` can fail with status 125, 126, or 127. What does each of those three values mean, and what kind of mistake causes each?

level: middleimportance: should knowfreq 52%

basics

~20 s

125 = the docker run command itself failed (bad flag, daemon or image-config error) — no container process ever ran. 126 = the command was found but could not be executed (not executable, bad format). 127 = the command was not found inside the image (typo, missing binary, wrong PATH).

open as a page

Two services are stopped the same way. One records exit code 143 and the other records 0. What accounts for the difference, and which outcome do you want in production?

level: middleimportance: should knowfreq 48%

basics

~20 s

143 means the process was killed by SIGTERM's default action — it ran no shutdown code. 0 means the process caught SIGTERM, shut down on its own terms, and exited successfully. In production you want 0: it proves graceful shutdown actually executed.

open as a page

When a container keeps crashing seconds after it starts, how does the Docker daemon pace its restart attempts, what limits the number of attempts, and what resets that pacing?

level: middleimportance: should knowfreq 38%

basics

~20 s

The daemon waits an exponentially growing delay between attempts — roughly 100 ms, doubling each time, up to a cap of about a minute — so a crash loop doesn't hammer the host. on-failure:N caps attempts; the delay and the counter reset once the container runs successfully for a short while.

open as a page

What does the `docker pause` command actually do to a container, how is it implemented in the Linux kernel, and how is it different from stopping the container?

level: middleimportance: should knowfreq 30%

basics

~20 s

docker pause freezes every process in the container using the kernel's freezer cgroup — no signal is sent, memory stays resident, nothing is scheduled. docker unpause resumes exactly where it left off. Stopping instead signals the process to terminate and frees its memory.

open as a page

Why does a container that has already exited still consume disk space, and what do `docker rm`, `docker rm -f`, `docker run --rm`, and `docker container prune` each do about it?

level: middleimportance: should knowfreq 44%

basics

~20 s

An exited container still exists as an object: its writable layer, logs, config and name are retained so you can inspect or restart it. docker rm deletes it and frees that space; docker rm -f kills a running one first; docker run --rm auto-deletes on exit; docker container prune bulk-removes all stopped containers.

open as a page

A Docker GPU container fails with `CUDA driver version is insufficient for CUDA runtime version`. How do you diagnose and fix it?

level: seniorimportance: should knowfreq 44%

basics

~20 s

The host's NVIDIA driver is older than the CUDA runtime in the image. Compare the driver version nvidia-smi reports inside the container with the image's CUDA version, then upgrade the host driver or rebuild on an older CUDA base.

open as a page

A Docker host runs out of disk and the culprit is a multi-gigabyte JSON log file under /var/lib/docker/containers. Explain why that happened and how you would configure the daemon so it cannot happen again.

level: seniorimportance: should knowfreq 50%

basics

~20 s

Docker's default json-file driver writes container output to an unbounded file on the host with no rotation. Set max-size and max-file on the driver — per container or as a daemon-wide default in /etc/docker/daemon.json — then restart the daemon and recreate containers.

open as a page

What makes a container health probe command useful rather than misleading, and what should it deliberately avoid testing?

level: seniorimportance: should knowfreq 50%

basics

~20 s

A good probe tests that this instance can serve — a cheap, dedicated endpoint that exercises the serving path — with a tight timeout and a binary that actually exists in the image. It should not test downstream dependencies, do real work, or require credentials, because that turns one dependency outage into every container reporting unhealthy.

open as a page

A team adds sshd and cron to their app's Docker image for access and scheduled jobs. What do you argue, and what do you offer instead?

level: seniorimportance: should knowfreq 44%

basics

~20 s

Both are VM habits. docker exec gives shell access with no second daemon, no keys in the image and no extra listener. Scheduled work belongs in its own container, run from the same image with a different command, so it has its own logs and exit code.

open as a page

What happens to running containers when the Docker daemon (`dockerd`) itself is stopped, restarted or upgraded, and what does the daemon's `live-restore` option change about that?

level: seniorimportance: should knowfreq 32%

basics

~20 s

By default, stopping the daemon stops all running containers; on daemon start they come back only if their restart policy says so. Enabling live-restore in daemon.json leaves containers running while the daemon is down — but only for patch-level daemon upgrades, and not in Swarm mode.

open as a page

What is a zombie process, why do they pile up inside containers in particular, and what do Docker's `--init` flag and the tini init process do about it?

level: seniorimportance: should knowfreq 38%

basics

~20 s

A zombie is a dead process whose exit status no parent has collected with wait(). Orphans are re-parented to PID 1, which must reap them. Application processes running as container PID 1 usually never call wait(), so zombies accumulate and can exhaust the PID table. --init inserts tini as PID 1, which reaps them.

open as a page

A `postgres` container ignores an updated `/docker-entrypoint-initdb.d` script on later starts. Why, and what do you do?

level: seniorimportance: should knowfreq 46%

basics

~20 s

The image's entrypoint runs /docker-entrypoint-initdb.d only when it initializes an empty data directory. With a persistent data volume already initialized, it skips straight to starting the server, so edited scripts never run. Schema changes belong in a migration tool.

open as a page

A workload already runs under an outer supervisor — a host init system such as systemd, or a cluster orchestrator that reschedules failed workloads. How do you decide what the container-level `--restart` policy should be, and where should responsibility for restarting live?

level: principalimportance: should knowfreq 30%

basics

~20 s

Exactly one layer should own restarts. If an outer supervisor starts and stops the container, set the container policy to no — otherwise two supervisors fight, and a workload the outer layer stopped keeps coming back. Docker's policy is for plain single-host deployments.

open as a page

You own a containerized service that both serves HTTP requests taking up to 20 seconds and consumes messages from a queue. Design its shutdown path: what should the process do on SIGTERM, and how do you choose the stop timeout it runs under?

level: principalimportance: should knowfreq 34%

basics

~20 s

On SIGTERM: fail readiness first, stop accepting new HTTP connections and stop pulling from the queue, finish or abandon in-flight work under a bounded deadline shorter than the stop timeout, flush and close, exit 0. Set the stop timeout above your worst realistic drain, not above your worst theoretical one.

open as a page

Why do Docker containers get only 64 MB of /dev/shm by default, and when do you raise it?

level: middleimportance: nice to knowfreq 30%

basics

~20 s

Docker mounts a 64 MB tmpfs at /dev/shm in every container. Workloads that pass bulk data between processes through POSIX shared memory exhaust it and die with a bus error rather than a clear message. Raise it with --shm-size.

open as a page

How can you add, change, or disable a container's health probe at `docker run` time without rebuilding the image, and when is that the right move?

level: middleimportance: nice to knowfreq 34%

basics

~20 s

docker run accepts --health-cmd, --health-interval, --health-timeout, --health-retries and --health-start-period to define or retune a probe, and --no-healthcheck to disable one entirely. Use them to tune against a real workload, or to override a base image's unsuitable check.

open as a page

Why run a CLI tool as a throwaway `docker run --rm` container instead of installing it on the host?

level: middleimportance: nice to knowfreq 29%

basics

~20 s

When you want a pinned tool version per project without installing it: docker run --rm starts a published image, runs one command against a mounted directory, then disposes of the container. Files it writes are owned by the user it ran as.

open as a page

How does `docker diff` help you find what a running container has written, and where does it mislead you?

level: seniorimportance: nice to knowfreq 27%

basics

~20 s

docker diff CONTAINER lists every path that differs from the container's image, prefixed A for added, C for changed and D for deleted. It shows no sizes, no file contents, and nothing under a volume or bind mount — so a disk problem in mounted storage is invisible to it.

open as a page

You find a container reported in the `dead` state, and `docker rm` refuses to remove it. What does that state actually mean, and how do you investigate and clean it up?

level: seniorimportance: nice to knowfreq 20%

basics

~20 s

dead means the daemon started tearing the container down and could not finish — usually a stuck mount or storage-driver error. The container cannot be started. Try docker rm -f; if that fails, find and unmount the leftover mounts under /var/lib/docker, then remove again, restarting the daemon if necessary.

open as a page

When would you accept more than one process in a single Docker container?

level: principalimportance: nice to knowfreq 30%

basics

~20 s

Rarely, and on conditions: when two concerns share a lifetime and a failure domain and the coupling cannot cross a container boundary, or when consuming a vendor image with its own process manager. Then demand signal forwarding, a non-zero exit on child failure, and stdout logging.

open as a page

showing 31–50 of 50