Struggling with the cannot kill Docker container – permission denied issue? Learn real causes, fixes, and commands that actually stop stuck containers without breaking your setup. Our Docker Live Support Team is always here to help you.
Running containers is usually smooth, right up until you try to stop one and get hit with the cannot kill Docker container – permission denied error. It shows up out of nowhere, blocks your work, and refuses to go away even after you try the usual commands. So here’s a clear, practical breakdown of why this happens and how you can fix it without wrecking your setup.
This guide is written from real-world cases where developers ran into the cannot kill Docker container – permission denied problem on Ubuntu, especially on systems running AppArmor. And since this issue can slow down even experienced admins, let’s get straight into every working fix.
Overview
Why This Error Happens
You’ll see the cannot kill Docker container – permission denied warning for a few common reasons:
- Docker daemon running with broken or restricted permissions
- A container started by a different user
- /var/run/docker.sock not accessible to your user
- AppArmor interfering with container shutdown
- A misconfigured entrypoint script
- Stuck docker-containerd-shim processes hanging onto resources
Although the root cause varies, many users discovered AppArmor playing a major role in blocking container actions.
Remove Unknown AppArmor Profiles
In many cases, AppArmor leaves behind “unknown” profiles that interfere with Docker. Removing them solves the issue instantly.
Run:
sudo aa-remove-unknown Once that command finishes, try stopping the container again:
docker stop <container_id> In most cases, this alone clears the cannot kill Docker container – permission denied problem.
Reload Docker Services
If the above didn’t help, reload system services:
sudo systemctl daemon-reload
sudo systemctl restart docker Then test again.
Restart containerd (Often the Real Culprit)
Sometimes the containerd runtime gets stuck, especially after long uptime.
sudo systemctl restart containerd This frees stuck containers without rebooting the host.
Kill Stuck Shim Processes
A hanging shim process is one of the most overlooked causes. Run:
sudo killall docker-containerd-shim After that, Docker regains control.
Clean Up Containers Properly
If you only want to stop running containers:
docker kill $(docker ps -q) If you want to remove all containers:
docker rm --force $(docker ps -a -q) Or prune stopped ones:
docker container prune AppArmor-Unconfined (Testing Only)
If you want to test whether AppArmor is the reason:
docker run --security-opt apparmor:unconfined -ti ubuntu bash Then try stopping it normally. This helps confirm the root cause without uninstalling anything.
Get Expert Docker Help Now!
Check Your Entrypoint Script
If your script uses:
#!/bin/bash -xe the system might block stop signals. Change it to:
#!/bin/bash -x Then rebuild your container.
Last Resort: Rebooting the Host
A full reboot does fix the problem, but it shuts down every running container. Use it only if all other fixes fail.
Conclusion
The cannot kill Docker container – permission denied error can feel like a wall, but these steps come from real fixes tested across multiple Linux setups. With these commands and explanations in your toolkit, you’ll overcome the issue without downtime, wasted hours, or broken environments.