Back to sections

Docker Interview Questions & Answers

A sample of real Docker interview questions with full answers and explanations - practice for interviews or certification exams.

easy

1. Which Docker daemon configuration mitigates container breakout?

Using bridge network driver
Setting --mtu=1500
Enabling --userns-remapCorrect
Increasing --log-level=debug

--userns-remap works by mapping container UIDs, including what LOOKS like root inside the container, to a completely unprivileged UID range on the actual host. That means even if an attacker somehow breaks out of container isolation entirely, they land as an unprivileged host user, not real root, which is exactly the containment this setting buys you.

medium

2. What does STOPSIGNAL SIGTERM do?

Sets the default signal for docker kill
Changes the signal sent to PID 1 on docker stopCorrect
Disables health checks
Kills the container immediately

By default, docker stop sends SIGTERM to a container's main process to ask it to shut down gracefully. STOPSIGNAL lets you override WHICH signal gets sent instead, useful for apps that expect a different signal (like SIGINT) to trigger their own graceful shutdown logic.

hard

3. You observe cgroup memory limit is set to 512MB, but free -m inside container shows total memory = host RAM. Why?

cgroup v1 doesn’t support memory limits
The container is using host network mode
free reads /proc/meminfo, which reflects host memory; apps should read /sys/fs/cgroup/memory/memory.limit_in_bytesCorrect
Memory limits only apply to disk cache

free reads /proc/meminfo, which isn't aware of cgroups at all, it just reports the HOST's total physical memory regardless of any per-container limit. To see the ACTUAL memory ceiling a container is bound by, an application needs to read the cgroup's own limit file directly instead of relying on tools like free.

easy

4. You run `docker run --network none nginx`. What happens to the container's networking?

It uses the macvlan driver to appear as a physical device on the local network
It automatically joins the default bridge network and receives a private IP address
It gets its own network namespace with no external interfaces at all, only a loopback interface, so it has no network connectivityCorrect
It shares the host machine's network namespace and interfaces directly

The `none` network driver still creates a separate network namespace for the container, so it isn't the same as the host's network, but it attaches no interfaces besides loopback, leaving it with no external connectivity at all. This is useful for containers doing offline or batch work that should never make network calls. Option B describes the DEFAULT bridge driver, and option C describes the `host` driver, which is the opposite of `none`: it removes network isolation entirely instead of maximizing it.

medium

5. What is the main risk of running a container with the `--privileged` flag?

It prevents the container from writing any files
It disables container networking entirely
It slows down container startup significantly
It gives the container nearly all capabilities of the host, weakening isolationCorrect

It doesn't kill networking, meaningfully slow startup, or block writes, none of those describe what `--privileged` actually changes. What it does is strip away most of the isolation Docker normally enforces, handing the container almost the same level of access to the host's devices and kernel that a process running directly on the host would have, which is a serious risk if that container is ever compromised.

hard

6. You’re running containers in Kubernetes. Which Docker-level hardening is redundant?

USER 1000 in Dockerfile
--read-only
--userns-remapCorrect
--cap-drop=ALL

--userns-remap is configured on the Docker DAEMON itself, but Kubernetes never actually calls docker run directly, it enforces its own equivalent protections (dropped capabilities, read-only filesystems, non-root users) directly through each pod's securityContext instead. So while the other three options still apply meaningfully in Kubernetes, this particular Docker-engine-level setting simply never comes into play.

easy

7. What does `docker-compose up` do?

Uploads an image to Docker Hub
Creates a new Dockerfile
Starts all services defined in a docker-compose.yml fileCorrect
Upgrades Docker to the latest version

Uploading is `docker push`, upgrading Docker is a system-level install/update task, and Compose doesn't generate Dockerfiles for you. `docker-compose up` reads the services listed in your docker-compose.yml and starts all of them together, which is the entire reason Compose exists: running multi-container apps with one command.

medium

8. You need two containers to communicate securely over localhost-like networking. What’s the best approach?

Create a user-defined bridge network and connect bothCorrect
Use --link (deprecated)
Use overlay network with Swarm
Use --network host

Host networking removes isolation entirely, and --link is deprecated and clunky. A user-defined bridge network is the modern, recommended answer here: it gives connected containers automatic DNS-based discovery by name, while still keeping them isolated from any unrelated containers that aren't on that same network.

hard

9. A container is started with --cpus=2 on an otherwise idle 8-core host. Under load, docker stats shows the container's CPU usage capping out well below what 6 idle cores could provide, and the app's response times spike periodically even though top inside the container never shows a sustained 100% usage. What's the most likely cause?

The cgroup CFS quota enforces the 2-core limit over fixed short time periods, so if the container bursts past its quota early in a period it gets throttled for the rest of that period, causing periodic latency spikes even when average usage looks fineCorrect
The host's CPU governor is throttling all cores, because Docker's default is to run in power-saving mode
docker stats and top read from different sources, and top inside a container is always inaccurate, so the discrepancy is just a display bug, not real throttling
--cpus only takes effect after the container has been running for several minutes, due to a cgroup initialization delay

--cpus=2 is implemented as a CFS quota and period pair, roughly 200ms of runtime per 100ms period, and the kernel enforces it per period: if the container's threads burn through that period's quota in a burst, they're throttled, effectively paused, until the next period starts. This shows up as periodic latency spikes rather than a smooth, evenly-distributed slowdown, and is a well-known cause of tail-latency issues in containerized services even when average CPU usage looks comfortably under the configured limit. Option D is a trap: the mismatch reflects a real kernel enforcement mechanism, not a monitoring bug.

easy

10. What is the purpose of the `docker login` command?

It signs Docker images with a GPG key to verify their authenticity before pushing
It starts the Docker daemon and requires a system password to unlock it
It authenticates the Docker CLI against a registry and stores credentials so subsequent push/pull commands can access private imagesCorrect
It creates a new user account inside a running container

`docker login` exchanges credentials for a token that Docker stores, by default in `~/.docker/config.json`, which is what lets later `docker pull` and `docker push` commands access private repositories without re-entering a password every time. It has nothing to do with starting the daemon itself or creating in-container users. Image signing is a separate feature, Docker Content Trust, and is not what `login` does.

Want to practice under real conditions?

Try the full timed Docker quiz.

    Welcome to OpsQuiz!

    Real scenario-based DevOps questions, hands-on practice, and clear explanations for every answer.