Unable to stop or remove a container in Docker, Permission denied is displayed

I have run several containers from an image in different ports, but I cant stop or remove these containers. I have run this command:

# sudo docker rm -f f85956145f61

And no message are displayed, however container is still displayed.

I have tried with these commands:

# docker stop $(docker ps -a -q)
# docker rm $(docker ps -a -q)

But I get the following error:

# Get http:///var/run/docker.sock/v1.15/containers/json?all=1: dial unix /var/run/docker.sock: permission denied

So, how can I remove all containers from my docker?

Upvotes: 5

Views: 13003

Answers (2)

beetree
beetree

Reputation: 941

Another reason for this happening is that the daemon is busy committing the container.

Upvotes: 1

Javier Cortejoso
Javier Cortejoso

Reputation: 9176

I don't know if you are trying to stop the container as root, but if not try to stop/kill the container as root or using sudo.

$ sudo docker kill $(docker ps -q)
$ sudo docker rm $(docker ps -a -q)

If this does not work try restarting docker service

$ sudo service docker restart

and then try again to stop and delete the container. If it doesn't work you can try to kill the process(es) running inside the container from your host machine.

And to reference the container in docker kill, docker stop, docker rm,... and so on, you can either specify the container id or the container name, both are valid.

Upvotes: 9

Related Questions