Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error response from daemon: Cannot kill container: permission denied, how to kill docker containers on Ubuntu 20.04?

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?

like image 786
0x55b1E06FF Avatar asked Sep 06 '25 16:09

0x55b1E06FF


2 Answers

what works for me in these cases:

sudo systemctl restart docker.socket docker.service
sudo docker image rm -f $(sudo docker image ls -q)
like image 114
dnvtrn Avatar answered Sep 09 '25 03:09

dnvtrn


It appeared that I had installed docker with snap as well as using the docker repository:

sudo snap list

So:

sudo snap remove docker --purge
sudo aa-remove-unknown

Along with re-installing Docker using the method described here solved my issues! No need to disable or remove apparmor.

like image 30
Omid Ariyan Avatar answered Sep 09 '25 05:09

Omid Ariyan