Linux Capabilities
Linux capabilities split root's power into about 40 individual privileges that can be granted or removed separately. Docker keeps a reduced default set, and --cap-drop ALL with selective --cap-add gives the tightest setup.
What capabilities are
Traditionally a process was either root, with all power, or unprivileged. Capabilities break root into pieces, such as NET_BIND_SERVICE (bind ports below 1024), CHOWN (change file ownership), SYS_PTRACE (trace processes), and SYS_ADMIN (a broad set of administrative operations). A process can hold only what it needs.
Docker's default set
Docker removes most capabilities from containers, even those running as root, and keeps these 14: AUDIT_WRITE, CHOWN, DAC_OVERRIDE, FOWNER, FSETID, KILL, MKNOD, NET_BIND_SERVICE, NET_RAW, SETFCAP, SETGID, SETPCAP, SETUID, and SYS_CHROOT. That is better than full root, but many apps need none of them.
Drop everything, add back what is needed
docker run -d --cap-drop ALL --name payment-api registry.example.com/payment-api:v3.1.0 # Needs port 80 inside the containerdocker run -d --cap-drop ALL --cap-add NET_BIND_SERVICE --name nginx nginx:1.27services: payment-api: cap_drop: - ALL cap_add: - NET_BIND_SERVICEOften the better fix is to listen on a high port such as 8080 and avoid adding any capability.
Check what a container holds
docker exec payment-api grep Cap /proc/1/status# CapEff: 0000000000000000 means nonecapsh --decode=00000000a80425fbCommon additions
NET_BIND_SERVICEfor ports below 1024.NET_ADMINfor tools that configure networking, such as some VPN clients.SYS_PTRACEonly for debugging, never in production.
Security
SYS_ADMINis nearly as powerful as root. Do not add it to production containers. Find a narrower capability or redesign.
Frequently Asked Questions
What problem do capabilities solve?
They replace the all-or-nothing root model with about 40 separate privileges, so a process can receive only the one it needs, such as binding a low port, without full root power.
Why drop all capabilities if I already run as non-root?
Non-root reduces damage in most cases, but retained capabilities can still be useful to an attacker exploiting a kernel flaw. Dropping all shrinks the attack surface in a way a non-root user alone does not.
How do I find which capability my app needs?
Start with --cap-drop ALL, run the workload, and add back only capabilities reported in permission errors. Test thoroughly, since some code paths use a capability only rarely.