Docker Run Command with --privileged Flag
Developers use the --privileged flag when running Docker containers to bypass permission issues or access hardware devices. This is often done as a quick fix for permission problems without understanding the security implications. The privileged flag removes all security restrictions imposed by the Linux kernel on the container.
Preview example – YAML
# VULNERABLE: Running container with full host access
docker run --privileged -d my-app:latest
# VULNERABLE: Docker compose with privileged containers
version: '3.8'
services:
webapp:
image: my-webapp:latest
privileged: true # Grants full host access
ports:
- "8080:8080"
database:
image: postgres:13
privileged: true # Unnecessary privileged access
environment:
POSTGRES_PASSWORD: secret
volumes:
- db_data:/var/lib/postgresql/data