Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 105/ 160
06. Docker Security & Hardening

Linux Capabilities (--cap-drop=ALL, --cap-add)

Drop all capabilities and add back only what the workload truly needs.

Advancedcap-drop · cap-add3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Express exact capabilities rather than --privileged, and verify them with a small denial test.

Think of it like…

Instead of granting the master key, hand over just the key for the supply cabinet and the loading-dock intercom.

Where you’ve seen it

In practice, docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1 is the concrete move for this job: drop all capabilities and add back only what the workload truly needs. The release is not accepted until capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount confirms the result.

Words you’ll hear

cap-drop
The implementation control in docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1 for drop all capabilities and add back only what the workload truly needs.
cap-add
The result to observe with capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount, rather than infer from a successful command alone.
Capabilities
The production boundary exposed when using --privileged to bind a low port when one capability and an unprivileged port would suffice.

Visual diagram

Loading interactive diagram

Theory & deep dive

cap-drop control path

The concrete mechanism is docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1. The observable result is capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount; if those disagree, inspect the runtime evidence before changing unrelated settings.

Drop all capabilities and add back only what the workload truly needs. Keep cap-drop, cap-add and Capabilities in the same deployment record so the intent and the observed state cannot drift apart.

Concrete cap-drop setup

docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1

Key takeaway: Prove cap-add with capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount, not with command success alone.

Capabilities failure boundary

Many teams add NET_ADMIN to solve a problem actually caused by missing route configuration, and SYS_ADMIN approximates broad host-administration power. Capabilities do not cover every isolation dimension such as seccomp, namespaces or mounted secrets. The narrow failure to design for is using --privileged to bind a low port when one capability and an unprivileged port would suffice.

Accept this compromise explicitly: A capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance. The controlled check-capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: using --privileged to bind a low port when one capability and an unprivileged port would suffice.

Key takeaway: A capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: Many teams add NET_ADMIN to solve a problem actually caused by missing route configuration, and SYS_ADMIN approximates broad host-administration power. Capabilities do not cover every isolation dimension such as seccomp, namespaces or mounted secrets.

Express exact capabilities rather than --privileged, and verify them with a small denial test.
Key numbers at this step
Intent
cap-drop

When to use it & trade-offs

What it is

Linux capabilities split selected root powers into units such as NET_BIND_SERVICE, CHOWN and SYS_ADMIN. Docker starts with a default capability set; --cap-drop=ALL removes them and --cap-add restores the minimum required privilege.

Why it matters: Many teams add NET_ADMIN to solve a problem actually caused by missing route configuration, and SYS_ADMIN approximates broad host-administration power. Capabilities do not cover every isolation dimension such as seccomp, namespaces or mounted secrets.

When to reach for it

  • The fit is strongest for this job: drop all capabilities and add back only what the workload truly needs. Pair it with capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount in the runbook.
  • Production cap-drop changes should make cap-add observable through docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1, rather than trusting the runtime default.
  • Keep a rollback example for the case where using --privileged to bind a low port when one capability and an unprivileged port would suffice.

When to avoid or be careful

  • Do not accept command success while the system can still fail by using --privileged to bind a low port when one capability and an unprivileged port would suffice.
  • Avoid erasing Capabilities protection merely to dodge this cost: “A capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance”.
  • Do not replace the evidence path-capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount-with a screenshot or a mutable tag.

docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1: practical choices

Explicit cap-drop
Best for: Drop all capabilities and add back only what the workload truly needs, with a reviewed runbook.

Strengths: Linux capabilities split selected root powers into units such as NET_BIND_SERVICE, CHOWN and SYS_ADMIN. Docker starts with a default capability set; --cap-drop=ALL removes them and --cap-add restores the minimum required privilege.

Watch out: A capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance.

Ambient default
Best for: Short-lived cap-add experiments with low blast radius.

Strengths: It can begin with docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1 and fewer surrounding controls.

Watch out: It silently accepts using --privileged to bind a low port when one capability and an unprivileged port would suffice, which makes the result hard to reproduce after promotion.

Managed Capabilities
Best for: Teams that centralize Capabilities policy across many workloads.

Strengths: Many teams add NET_ADMIN to solve a problem actually caused by missing route configuration, and SYS_ADMIN approximates broad host-administration power. Capabilities do not cover every isolation dimension such as seccomp, namespaces or mounted secrets.

Watch out: The platform adds an ownership and debugging layer; retain capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount as the direct check.

Interview signals & numbers to know

When this topic comes up

  • docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1
  • capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount
  • Failure signature: using --privileged to bind a low port when one capability and an unprivileged port would suffice
  • Trade-off: A capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance.

Benchmarks & rules of thumb

0 capabilities -
initial state after cap-drop=ALL
NET_BIND_SERVICE -
example single restored capability
CAP_SYS_ADMIN -
a very broad capability that is often a warning sign

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1 as proof and skipping capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount.
  • Using --privileged to bind a low port when one capability and an unprivileged port would suffice
  • Optimizing cap-drop without accepting that a capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance.

Likely interviewer follow-ups

  • Why does docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1 address cap-drop here rather than through application code?
  • How would you distinguish healthy cap-add from the failure “using --privileged to bind a low port when one capability and an unprivileged port would suffice” using capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount?
  • When would this trade-off-“A capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance”-justify a different Capabilities design?
Interview tip: Give one concrete operation-docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1-and one proof-capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount. Then name the boundary: using --privileged to bind a low port when one capability and an unprivileged port would suffice.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Linux Capabilities (--cap-drop=ALL, --cap-add) with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
User Namespaces & UID/GID Remapping
Next topic
Preventing Privilege Escalation (--security-opt=no-new-privileges)