Docker & Containerization Engineering Master Interview Bank
Linux namespaces, cgroups, UnionFS / overlay2 storage drivers, multi-stage Docker builds, image layer caching, rootless Docker, and container security.
Curriculum Roadmap & Learning Path
3 StagesPart 1: Basic & Foundational Concepts (Junior / Entry-Level)
12 QuestionsWhat is Docker, and what is the difference between an Image and a Container?
Docker is an open-source platform that packages applications and all their dependencies into a standardized, isolated executable unit called a • Docker Image: An immutable, read-only template or blueprint containing the OS libraries, runtime, application code, and default configuration.
Containers vs. Virtual Machines (VMs): How do Linux Namespaces and Control Groups (cgroups) isolate processes?
Virtual Machines: Virtualize physical hardware via a Hypervisor (Type 1 like ESXi or Type 2 like VirtualBox) • Containers: Virtualize at the operating system level • Namespaces (Isolation): Restricts what a process can see • Control Groups / cgroups (Resource Metering): Restricts how much a process can use.
What is a Dockerfile and what are its essential instructions?
A Dockerfile is a plain text file containing sequential instructions that Docker executes to assemble an image.: FROM: Sets the base parent image (e.g., FROM node:20-alpine) • WORKDIR: Sets the working directory for subsequent instructions (WORKDIR /app).
What is the difference between `CMD` and `ENTRYPOINT` in Docker?
ENTRYPOINT: Defines the core executable that will always run when the container starts • CMD: Provides default arguments or parameters to the ENTRYPOINT • Overriding behavior • CMD is easily overridden by passing arguments at the end of docker run.
What are Docker Volumes, Bind Mounts, and tmpfs mounts? How do they differ?
Containers have ephemeral writable filesystems; when a container is deleted, its data is permanently lost. Docker provides three persistent storage mechanisms: Named Volumes (docker run -v my_data:/data): Managed entirely by Docker inside the host's /var/lib/docker/volumes/ directory.
What is the difference between `docker run`, `docker start`, `docker stop`, and `docker kill`?
docker run: Combines docker create (pulls image and allocates container layer) and docker start (executes process) • docker start: Starts an existing, stopped container without recreating its container filesystem layer • docker stop: Gracefully stops a running container.
How does Docker port mapping (`-p` vs `-P`) work?
By default, container network ports are inaccessible from outside the host machine.: p : (Explicit Mapping): Maps a specific port on the host to a port inside the container.
What is Docker Compose, and when is it used instead of raw Docker commands?
Docker Compose is a declarative tool for defining and running multi-container Docker applications using a single YAML file (docker-compose.yml).: Instead of running 5 separate docker run commands with complex network, environment, and volume flags, a single docker compose up -d brings up.
What are the common Docker networking modes (`bridge`, `host`, `none`, `overlay`)?
bridge (Default): Creates a virtual bridge network (docker0 on Linux) • host (--net=host): Disables network isolation entirely • none (--net=none): Completely isolates the container network stack • overlay: Enables multi-host container networking across distinct physical Docker daemon nodes (used in Docker Swarm and Kubernetes clusters).
How do you view container logs, inspect container state, and open an interactive shell inside a running container?
Interactive Shell.
What is the `.dockerignore` file and why is it critical for build speed and security?
When you run docker build ., the Docker CLI transfers everything in the current directory (the Build Context) across the Docker socket to the build daemon. A .dockerignore file excludes unnecessary files from this transfer: Speeds up builds: Avoids sending hundreds of megabytes of node_modules.git, or build caches over the socket.
What are dangling images, and how do you clean up disk space using `docker system prune`?
Dangling Images (:): Untagged image layers left behind when you build a new image with an existing tag (e.g., rebuilding myapp:latest) • Cleanup Commands.
Part 2: Core Architecture & Implementation (Mid-Level)
12 QuestionsContainer Storage & UnionFS / Overlay2: How does the Copy-on-Write (CoW) mechanism work in Docker?
Docker images are built as a stack of immutable, read-only layers. When a container runs, Docker attaches a single, thin, read-write layer on top known as the Container Layer. Docker implements this filesystem stack using the Overlay2 storage driver (Linux OverlayFS).
How do Multi-Stage Docker Builds reduce production image size and protect build secrets?
Traditional Dockerfiles included compilers, SDKs, build tools, package managers, and test runners in the final image, bloating size to gigabytes and increasing the security attack surface. Multi-Stage Builds allow you to define multiple FROM lines in a single Dockerfile.
How does Docker build layer caching work, and how should instructions be ordered to maximize cache hits?
Docker executes Dockerfile instructions from top to bottom. Each instruction generates a layer cached by cryptographic hash.: For RUN, Docker checks if the command string matches a cached layer • For COPY and ADD, Docker computes checksums of local files.
How do you implement Docker health checks (`HEALTHCHECK`) and how do orchestrators consume them?
By default, Docker only checks if PID 1 is alive. If your web server deadlocks, exhausts database connections, or enters an infinite loop, the container remains in the Up state even though it cannot serve requests. The HEALTHCHECK instruction tells Docker how to test if the service is genuinely healthy.
What are Distroless and Alpine base images, and what are their trade-offs (`glibc` vs `musl libc`)?
Alpine Linux (alpine) • Uses musl libc and BusyBox • Trade-off: musl libc has known performance overhead with certain memory allocators, and compiled native C-extensions (like Python numpy, Node • Distroless Images (GoogleContainerTools).
Why is running containers as root a major security vulnerability, and how do you secure runtime privileges?
By default, UID 0 inside a container is UID 0 on the host Linux kernel unless User Namespaces are enabled. If an attacker achieves Remote Code Execution (RCE) inside a container running as root: Any breakout (via kernel vulnerability, container escape, or mounted Docker socket) grants root access to the entire host server.
How do you manage secrets securely in Docker without baking them into image layers?
Never use ENV or ARG for sensitive tokens or passwords.: Values passed to ARG or ENV are permanently visible in docker history and stored in plaintext image metadata layers! • BuildKit Secret Mounts (Build time).
What is BuildKit and what advanced features does it provide?
BuildKit is the modern Docker build engine (enabled by default in modern Docker CLI or via DOCKER_BUILDKIT=1). It replaces the legacy serial build execution graph with an optimized Directed Acyclic Graph (DAG).: Parallel Stage Execution: Independent stages in a multi-stage Dockerfile execute concurrently across multiple CPU cores.
What are Docker restart policies (`no`, `on-failure`, `always`, `unless-stopped`)?
Controls whether containers automatically restart after process termination or Docker daemon reboot: no (Default): Container never restarts regardless of exit code • on-failure[:max-retries]: Restarts only if the container exits with a non-zero exit code.
How do you limit CPU, memory, and swap resources for a Docker container?
Without resource constraints, a single runaway memory leak or infinite loop in a container can starve the host OS and trigger the Linux kernel Out-Of-Memory (OOM) killer against critical host daemons.
How does Docker logging work and how do you prevent log files from exhausting host disk space?
By default, Docker captures all stdout and stderr streams from PID 1 and writes them as JSON files to /var/lib/docker/containers//-json.log. Without log rotation, a chatty application will eventually consume 100% of host disk space, crashing the server! #### Configuring Global Log Rotation (/etc/docker/daemon.json).
How do Multi-Architecture builds (`docker buildx`) work for deploying on x86_64 (amd64) and ARM64?
Developers often build images on ARM64 chips (Apple Silicon M1/M2/M3), but production servers frequently run on AMD64 (Intel/AMD) or AWS Graviton (ARM64). Running an AMD64 image on ARM64 requires slow emulation.
Part 3: Advanced Internals, Scale & Production Security (Senior / Lead)
26 QuestionsDeep Dive into the 7 Linux Namespaces: How the Kernel Implements Container Isolation.
Namespaces wrap global system resources in an abstraction such that processes within the namespace believe they have their own isolated instance of that resource.: PID (Process IDs): Isolates process IDs • NET (Networking): Isolates network devices, IP routing tables, port bindings, and firewall iptables.
Linux Control Groups (cgroups v1 vs cgroups v2): Memory OOM-killer Behavior and CPU CFS Bandwidth Quotas.
cgroups regulate resource allocation and hardware throttling: cgroups v1: Had separate, uncoordinated hierarchies per resource controller (/sys/fs/cgroup/cpu, /sys/fs/cgroup/memory) • cgroups v2: A single unified hierarchy tree • Period: cpu.cfsperiodus (default: 100,000 microseconds = 100ms).
Container Runtime Architecture: What is the relationship between Docker CLI, Dockerd, Containerd, runc, and OCI?
Modern container infrastructure is decoupled into layered, open-standard components governed by the Open Container Initiative (OCI).
Linux Capabilities and Seccomp Profiles: Dropping Privileges and Syscall Filtering.
Traditional Unix has a binary permission model: either a process is unprivileged (UID > 0) or all-powerful root (UID 0). Linux Capabilities divide root privileges into ~40 granular permissions. #### 1. Dropping Unnecessary Capabilities.
Read-Only Root Filesystems (`--read-only`): Immutable Container Hardening.
A golden rule of high-security container operations is ensuring that the container root filesystem is mounted as read-only.
Rootless Docker: Running the Daemon and Containers as a Non-Privileged User.
Standard Docker requires the dockerd daemon to run as host root (root:root). Any access to /var/run/docker.sock is equivalent to root access on the host. Rootless Docker runs both dockerd and containers inside a non-root user namespace without root privileges.: Uses newuidmap and newgidmap to allocate UID/GID ranges.
Container Image Vulnerability Scanning and Cryptographic Image Signing.
Production CI/CD pipelines must verify both the integrity and security posture of container images before deployment: Scans OS packages (Debian dpkg, Alpine apk) and language dependencies (package-lock.json, Cargo.lock, go.sum) against the National Vulnerability Database (NVD).
Docker Daemon Configuration (`daemon.json`): Live-Restore, Default Address Pools, and Logging Drivers.
The /etc/docker/daemon.json file configures the host-level Docker engine. Key production settings.
Debugging Crashing Containers: PID 1 Zombie Reaping and Signal Handling (`tini` / `dumb-init`).
In Unix, Process ID 1 (PID 1) has special kernel duties: Signal Handling: By default, the Linux kernel ignores SIGTERM for PID 1 unless the process explicitly registers a signal handler • Zombie Reaping: When child processes terminate, they become zombies until their parent reaps them with wait().
High-Performance Container I/O: Shared Memory (`/dev/shm`), Hugepages, and Host Networking.
Default container configurations can cripple high-throughput databases (Postgres, Redis) or ML workloads (PyTorch): Shared Memory Limit: Docker defaults /dev/shm to a meager 64MB • Hugepages (--sysctl vm.nr_hugepages=1024): Bypasses 4KB page table traversal overhead for in-memory databases.
Architecting an Enterprise Golden Image Pipeline & Container Governance.
In large enterprises with hundreds of microservices, letting each team write arbitrary Dockerfiles from scratch leads to security vulnerabilities and bloated images.
Linux Namespaces and cgroups v2: The Foundation of Containers.
Containers are not lightweight virtual machines; they are standard Linux processes isolated by two kernel primitives: Namespaces (Isolation - What a process can see) • pid: Process isolation (container process thinks it is PID 1) • net: Isolated network interfaces, routing tables, and IP ports • mnt: Independent filesystem mount points.
OverlayFS Storage Driver: Copy-on-Write (CoW) Architecture.
Docker uses OverlayFS to layer read-only image layers into a single unified filesystem: lowerdir: Read-only base image layers stacked on top of each other • upperdir: Read-write layer unique to the running container • merged: Unified mount directory presented to the container process.
Multi-Stage Builds & Distroless Images: Shrinking Images by 95%.
Shipping build tools (compilers, npm, Maven, SDKs, bash) into production container images creates massive 1GB+ bloated images riddled with CVE security vulnerabilities: Multi-Stage Build: Compile code in a fat build stage, then copy only the final compiled artifact into a minimal runtime base image.
Docker BuildKit: Parallelism, Cache Mounts, and Secret Mounts.
BuildKit (DOCKER_BUILDKIT=1) modernizes the Docker build engine: Parallel Stage Execution: Independent build stages execute concurrently across CPU cores • Cache Mounts (--mount=type=cache,target=/root/.cache): Persists package manager caches (npm, Maven, Go modules) across builds without baking.
Container Networking Modes: Bridge, Host, Overlay, and Macvlan.
Bridge (Default bridge): Creates a virtual bridge (docker0) on host with NAT port mapping (-p 8080:80) • Host (--network host): Bypasses network isolation • Overlay: Multi-host networking spanning across multiple physical Docker hosts (powers Docker Swarm and Kubernetes Pod networks).
Container Security Hardening: Non-Root, Read-Only, and Dropping Capabilities.
Three golden rules to prevent container breakout exploits: Run as Non-Root: USER 10001:10001 • Read-Only Root Filesystem (--read-only): Prevents attackers from downloading malicious scripts, web shells, or cryptocurrency miners into /tmp • Drop Capabilities (--cap-drop=ALL): Linux divides superuser privileges into discrete capabilities.
Signal Handling and the PID 1 Zombie Process Problem.
When a process runs as PID 1 inside a container, Linux kernel default signal handlers are disabled. If a Java or Node.js process runs as PID 1: It ignores standard SIGTERM signals sent by docker stop, forcing Docker to hang for 10 seconds before violently killing it with SIGKILL (causing.
Vulnerability Scanning & SBOM Generation.
Trivy / Grype: Scans container images in CI/CD pipelines, analyzing OS packages (Alpine/Debian) and application dependencies (npm, PyPI, Go) • Software Bill of Materials (SBOM): Comprehensive inventory of every software component, library, and license bundled inside a container image.
Docker Storage: Volumes vs Bind Mounts vs Tmpfs.
Volumes (docker volume create): Managed by Docker in /var/lib/docker/volumes/ • Bind Mounts (-v /host/dir:/container/dir): Mounts an arbitrary host directory into the container • Tmpfs Mounts (--tmpfs /app/cache): Stored exclusively in host system RAM, never written to disk.
Docker Compose: Production Healthchecks and Startup Dependencies.
Using dependson: [db] only waits for the database container to start running, not for the database engine to finish initializing!: Use Healthchecks with condition: servicehealthy to ensure the web service starts only after the database is fully ready to accept client connections.
Multi-Architecture Builds with Docker Buildx.
Developers building on Apple Silicon (M1/M2/M3 - arm64) must build images compatible with production cloud servers (amd64 / x86_64).: docker buildx build --platform linux/amd64,linux/arm64 -t myimage:latest --push .
Memory Limits and the Linux Out-Of-Memory (OOM) Killer.
If a container has no memory limit (--memory), a memory leak will consume all host RAM, prompting the Linux kernel OOM Killer to terminate critical system processes!: Set hard limits: --memory="2g" --memory-swap="2g".
Container Logging Drivers and Log Rotation.
By default, Docker writes stdout/stderr logs to JSON files (json-file). Without configuration, high-traffic applications generate hundreds of gigabytes of logs, filling up the server hard drive and crashing the host!: Mitigation: Configure log rotation in /etc/docker/daemon.json.
The OCI (Open Container Initiative) Specifications.
The OCI is an open governance body standardizing container virtualization: Image Spec: Defines image archive layout, manifests, and layers • Runtime Spec (runc): Defines how to unpack and run an OCI container image using Linux namespaces and cgroups.
Rootless Docker: Eliminating Privilege Escalation.
Standard Docker runs the dockerd daemon as host root. A user with access to the Docker socket can easily mount the host filesystem and take over the entire server.: Rootless Docker: Runs the Docker daemon and containers inside a user namespace without root privileges.