Linux Capabilities in Docker: Understanding Default Permissions and Hardening
Deep dive into Linux capabilities in Docker containers, default capabilities like CAP_NET_BIND_SERVICE and CAP_CHOWN, using --cap-add and --cap-drop, and dropping root privileges.
Published on • November 17, 2026
AI Assistant

By default, Docker containers execute process commands as the root user (UID 0). In standard Linux environments, UID 0 holds unrestricted privileges to perform any action on the system. However, running processes inside containers as root does not give them total control over the host kernel. Docker leverages Linux Capabilities (capabilities(7)) to slice traditional root permissions into distinct, granular privilege units.
Understanding how Docker assigns default capabilities, how to strip unnecessary privileges, and how to safely grant specific permissions is essential for container security and hardening.
What Are Linux Capabilities?
Historically, Linux divided processes into two categories: privileged (effective UID is 0) and unprivileged (effective UID is non-zero). Privileged processes bypassed all kernel permission checks, while unprivileged processes were checked against file permissions and access control lists.
Linux capabilities break down traditional superuser privileges into smaller, independent flags. Kernel permission checks test whether a process holds a specific capability rather than checking if UID == 0.
Traditional Linux Security Model:
Full Root Privileges (UID 0) ──► Complete Control (Kernel, Hardware, Filesystem)
POSIX Capabilities Security Model:
UID 0 divided into ~40 granular capabilities:
├─ CAP_CHOWN (Change file ownership)
├─ CAP_NET_BIND_SERVICE (Bind sockets to ports < 1024)
├─ CAP_KILL (Bypass permission checks for sending signals)
└─ CAP_SYS_ADMIN (Blocked by default: mount filesystems, load drivers)
Default Capabilities Granted by Docker
When you execute docker run without custom security flags, Docker creates a container with a restricted subset of capabilities (14 default capabilities in standard installations). Even though the container user is root, it cannot perform high-risk kernel operations like mounting host filesystems, modifying kernel parameters, or reconfiguring network interfaces.
Here is the default capability set granted to unprivileged Docker containers:
| Capability | Description | Common Use Case |
|---|---|---|
CAP_CHOWN | Make arbitrary changes to file UIDs and GIDs. | File permission setup during package installs. |
CAP_DAC_OVERRIDE | Bypass file read, write, and execute permission checks. | Root file modifications. |
CAP_FOWNER | Bypass permission checks on operations that require file ownership. | chmod on files owned by other users. |
CAP_FSETID | Don’t clear setuid and setgid bits when a file is modified. | Setting sticky bit permissions. |
CAP_KILL | Bypass permission checks for sending signals to processes. | Stopping or signalling processes (kill -9). |
CAP_SETGID | Make arbitrary manipulations of process GIDs. | Switching process group identity (su/sudo). |
CAP_SETUID | Make arbitrary manipulations of process UIDs. | Switching process user identity (su/sudo). |
CAP_SETPCAP | Transfer and modify capability sets on processes. | Privilege management within capability boundaries. |
CAP_NET_BIND_SERVICE | Bind a socket to Internet domain privileged ports (port numbers < 1024). | Binding web servers to port 80 or 443. |
CAP_SYS_CHROOT | Use chroot() to change root directory. | Creating sandbox directory structures. |
CAP_MKNOD | Create special device files using mknod(). | Device node creation. |
CAP_AUDIT_WRITE | Write records to kernel auditing log. | Security event logging. |
CAP_SETFCAP | Set file capabilities on executables. | Fine-grained binary privilege assignment. |
Powerful Capabilities Blocked by Default
Docker strips dangerous capabilities by default, protecting host stability:
CAP_SYS_ADMIN: Over 50 administrative kernel functions (mount, cgroups, swap space).CAP_NET_ADMIN: Reconfiguring host interfaces, IP routing tables, firewall rules.CAP_SYS_PTRACE: Tracing arbitrary processes usingptrace(prevents memory inspection container breakout).CAP_SYS_MODULE: Loading and unloading Linux kernel modules dynamically.
Managing Capabilities with --cap-add and --cap-drop
Docker CLI provides explicit flags to add or remove capabilities when running containers.
Inspecting Container Capabilities
You can inspect active capabilities inside a container using capsh (from the libcap2-bin package):
docker run --rm alpine capsh --print
Output highlights the bounding and effective capability set:
Current: = cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_sys_chroot,cap_mknod,cap_audit_write,cap_setfcap+eip
Bounding set =cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_sys_chroot,cap_mknod,cap_audit_write,cap_setfcap
Adding Specific Capabilities (--cap-add)
If a container application requires specific administrative abilities (such as Network Time Protocol or raw network socket manipulation for ping), grant only the minimal required capability:
# Granting CAP_NET_ADMIN for VPN or network manipulation
docker run -d --name vpn-client \
--cap-add=NET_ADMIN \
custom-vpn-image
# Granting CAP_SYS_TIME to allow clock adjustment inside dedicated test container
docker run --rm \
--cap-add=SYS_TIME \
alpine date -s "2026-11-17 12:00:00"
Dropping Unnecessary Capabilities (--cap-drop)
To minimize attack surface, remove capabilities that your application does not need. For example, if a microservice does not need to change file ownership or set file capabilities:
docker run -d --name secure-api \
--cap-drop=CHOWN \
--cap-drop=SETUID \
--cap-drop=SETGID \
node:20-alpine
Principle of Least Privilege: --cap-drop=ALL
The ultimate security best practice for container hardening is to drop all capabilities by default, and then selectively add back only those essential for application startup:
docker run -d --name hardened-nginx \
--cap-drop=ALL \
--cap-add=NET_BIND_SERVICE \
--cap-add=CHOWN \
--cap-add=SETUID \
--cap-add=SETGID \
nginx:alpine
In Docker Compose (compose.yaml):
services:
web:
image: nginx:alpine
cap_drop:
- ALL
cap_add:
- NET_BIND_SERVICE
- CHOWN
- SETUID
- SETGID
security_opt:
- no-new-privileges:true
Combining Capability Hardening with Non-Root Users
Removing capabilities restricts the actions of the root user, but the recommended approach is combining non-root container users (USER 10001) with dropped capabilities.
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
# Switch to unprivileged user
USER node
EXPOSE 3000
CMD ["node", "server.js"]
When running as non-root user node (UID 1000), even if a capability is listed in the bounding set, the process lacks root privileges to execute restricted syscalls, creating defense-in-depth security.
Takeaway:
Docker isolates container processes by stripping dangerous Linux capabilities by default while retaining a subset of 14 standard capabilities (like CAP_NET_BIND_SERVICE and CAP_CHOWN). To harden production containers against exploitation, apply the principle of least privilege by dropping all capabilities (--cap-drop=ALL) and explicitly adding back only those strictly required by your application runtime.