I’m trying to kill a docker container, but I got permission denied. I use Ubuntu 20.04, my docker version for client is 20.10.7 and the one for the server is 20.10.11.
This is the log I got:
Error response from daemon: Cannot kill container: fastapi_server: permission denied
I read that I should use this comand for restarting docker.
sudo systemctl restart docker.socket docker.service
But the thing is that when I execute this command, all my containers and images dissapear, but If I try on localhost:8000 my port is occupied by the container that I wanted to delete. And if I run sudo netstat -anp | grep 8000
, I get:
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 2493/docker-proxy
tcp6 0 0 :::8000 :::* LISTEN 2500/docker-proxy
So this confirms that my port is already taken by a docker container, but when I run docker ps -a
, I get no container. I also tried docker kill
, but it did not work.
How should I kill this container & get my 8000 port free?
6
Answers
Try these steps:
Find the PID AND kill that process.
If that does not work check with
everything related to Docker. You can put output here that we can help you.
Ok,from you png ist seems that you have problem with AppArmor. Try this:
Please think twice before removing
AppArmor
. To my understanding this is central to application security for instance on recent major Ubuntu versions.It seems the rights problem is specific to a Docker version. Assuming yours is also installed via snap, please attempt upgrading your Docker version to at least the current beta, e.g. with
20.10.12
seems to work fine.(In fact I fell for the suggestion and did remove my AppArmor – snaps went away. Then reinstalled ASAP, the settings of relevant snaps are still with me – afterwards installed docker back, had the problem, upgraded it: seems to work like a charm.)
It appeared that I had installed docker with snap as well as using the docker repository:
So:
Along with re-installing Docker using the method described here solved my issues! No need to disable or remove apparmor.
I installed Docker from snap and experienced the permission denied error response. After reading many users experiencing more problems with the apparmor suggestion, I uninstalled Docker from snap, then used digitalocean’s Docker installation tutorial.
It worked for me, posting here as reference for others experiencing the same problem.
what works for me in these cases:
In my case it was also apparmor on Ubuntu 20.04 after upgrade from Bionic. By running dmesg I got error message:
To fix this please edit /etc/apparmor.d/docker and add to the beginning (however, after the ‘profile docker-default …. {‘ ) the following line:
Then reload apparmor
This fixed it at least on my computer.
See more https://manpages.ubuntu.com/manpages/xenial/man5/apparmor.d.5.html under section signal: