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 pageshowhide
explore
- Container States & Commands6 questions
- Signals & the PID 1 Problem5 questions
- Restart Policies5 questions
- exec, attach & Logs4 questions
- Runtime Health Checks5 questions
- Exit Codes5 questions
- Resource Limits & OOM4 questions
- Copy, Commit & Export4 questions
- Device & GPU Access4 questions
- One Process per Container4 questions
- Running Third-Party Images4 questions
- Dockerskillanchors this topic
- AI Engineerrole
- Backend Developerrole
- Data Engineerrole
- DevOps / SRE Engineerrole
- DevSecOps Engineerrole
- Forward Deployed Engineerrole
- Full Stack Developerrole
- Java Backend Developerrole
- Java SDETrole
- Kotlin Backend Developerrole
- MLOps Engineerrole
- Machine Learning Engineerrole
- PostgreSQL DBArole
- QA Engineerrole
- Server-Side Game Developerrole
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?
basics
~20 s125 = 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).
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?
basics
~20 s143 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.
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?
basics
~20 sThe 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.
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?
basics
~20 sdocker 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.
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?
basics
~20 sAn 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.
A Docker GPU container fails with `CUDA driver version is insufficient for CUDA runtime version`. How do you diagnose and fix it?
basics
~20 sThe 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.
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.
basics
~20 sDocker'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.
What makes a container health probe command useful rather than misleading, and what should it deliberately avoid testing?
basics
~20 sA 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.
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?
basics
~20 sBoth 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.
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?
basics
~20 sBy 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.
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?
basics
~20 sA 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.
A `postgres` container ignores an updated `/docker-entrypoint-initdb.d` script on later starts. Why, and what do you do?
basics
~20 sThe 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.
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?
basics
~20 sExactly 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.
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?
basics
~20 sOn 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.
Why do Docker containers get only 64 MB of /dev/shm by default, and when do you raise it?
basics
~20 sDocker 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.
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?
basics
~20 sdocker 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.
Why run a CLI tool as a throwaway `docker run --rm` container instead of installing it on the host?
basics
~20 sWhen 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.
How does `docker diff` help you find what a running container has written, and where does it mislead you?
basics
~20 sdocker 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.
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?
basics
~20 sdead 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.
When would you accept more than one process in a single Docker container?
basics
~20 sRarely, 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.
showing 31–50 of 50