Docker Best Practices #1: Avoid unnecessary privileges

One of the ways to ensure unnecessary privileges are avoided is through rootless containers. This means “No Root on the host”. Traditional Docker requires a Daemon (dockerd) run as root. This means that any breakout vulnerability gives an attacker host-level access, and even non-privileged users can indirectly trigger root-level operations through the Daemon. The rootless docker flips this model making everything - the Daemon, the CLI, and the containers - runs under an ordinary user account. No root privileges are needed on the host, hence reducing the radius of any compromise.

Furthermore, rootless containers rely on user namespaces, which map container’s internal root - a non-privileged user ID on the host. Even if a process inside the container thinks it's root, it's actually just a regular user outside. This prevents privilege escalation and aligns perfectly with the principle of least privilege.

Moreover, do not bind to a specific UID. While running containers as a non-root user, that user UID should not be made a requirement. Resources should be world-readable (that is 0644 instead of 0640) ensuring everything works if UID changes.

Also, every executable in a container should be owned by the root user, even if it is to be executed by a non-root user. Such executables should not be world-writable. A resource is considered world-writable when any user on the system is allowed to write to it - not just the owner or a specific group.