skip to Main Content

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


  1. Try these steps:

    docker inspect
    

    Find the PID AND kill that process.

    If that does not work check with

    dmesg
    

    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:

    sudo apt purge --auto-remove apparmor
    sudo service docker restart
    docker system prune --all --volumes
    
    Login or Signup to reply.
  2. 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

    snap refresh docker --beta
    

    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.)

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
  4. 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.

    Login or Signup to reply.
  5. what works for me in these cases:

    sudo systemctl restart docker.socket docker.service
    sudo docker image rm -f $(sudo docker image ls -q)
    
    Login or Signup to reply.
  6. In my case it was also apparmor on Ubuntu 20.04 after upgrade from Bionic. By running dmesg I got error message:

    [1113458.482007] audit: type=1400 audit(1672134271.112:1718): apparmor="DENIED" operation="signal" profile="docker-default" pid=1654 comm="dockerd" requested_mask="receive" denied_mask="receive" signal=kill peer="snap.docker.dockerd
    

    To fix this please edit /etc/apparmor.d/docker and add to the beginning (however, after the ‘profile docker-default …. {‘ ) the following line:

     signal,
    

    Then reload apparmor

     sudo systemctl 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:

    Example AppArmor signal rules:
    
           # Allow all signal access
           signal,
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search