14

I'm trying to remove a docker/image/container and all stuff which is somehow connected with docker, but first of all I need to stop it. While I'm trying to execute this command:

docker stop $(docker ps -a -q)

It gives me an error:

[:/home/imran] 1 $ docker stop $(docker ps -a -q)

2015/01/16 00:37:38 Get http:///var/run/docker.sock/v1.14/containers/json?all=1: dial unix /var/run/docker.sock: permission denied

Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]  

Stop a running container by sending SIGTERM and then SIGKILL after a grace period

  -t, --time=10      Number of seconds to wait for the container to stop before killing it. Default is 10 seconds.

How can I uninstall a docker container?

2 Answers 2

12

I've fixed it! Please don't forget - all your data in the containers will be removed!

So, first of all we need to execute this commands:

# adding new group
$ sudo groupadd docker

# adding user to the 'docker' group
$ sudo gpasswd -a ${your_username} docker

# restart the docker (documentation suggests to use 'docker.io' instead of 'docker',
# for me both variants work just fine!
$ sudo service docker restart

Then we need to logout, DON'T use GUI-variant because it didn't work for me and i was dissapointed about this.

Instead, use this command:

sudo pkill -u username

Then we need to...

1. Kill all running containers

sudo docker kill $(docker ps -q)

2. Delete all stopped containers

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

3. Delete all 'untagged/dangling' images

sudo docker rmi $(docker images -q -f dangling=true)

4. Delete all images

sudo docker rmi $(docker images -q)

Sources:
https://www.calazan.com/docker-cleanup-commands/
http://www.linuxquestions.org/questions/ubuntu-63/how-do-i-log-out-via-terminal-928183/

P.S. Maybe other answers are correct too, but at the moment these answers were published my problem was already fixed and I'm unable to check if they are correct or not. Thanks to @Andreas. He pointed out a mistake that containers were already removed. Since I didn't find any correct and "all in one" sollution I wanna tell you how you can fix it.

1
  • How do you remove the remain IP routing from ifconfig? docker still shows up as a network device
    – 6ft Dan
    Feb 12, 2016 at 2:16
3

You need to execute these commands as root, i.e. using sudo:

sudo docker stop $(sudo docker ps -a -q)

Or:

sudo sh -c "docker stop $(docker ps -a -q)"
4
  • Is this a normal output: pastebin.com/FXhc5TF7 . Also I've noticed my "cmd-label" is changed. From 'user@rootf8fds7$: ' to '[:/home/imran]'
    – pushandpop
    Jan 16, 2015 at 14:37
  • Probably this means that there are no running containers. Check by simply running sudo docker ps. Jan 16, 2015 at 15:20
  • Yeah, you're right, I've tried another method before you've wrote your answer and this because they don't exist xD. What about problem with "cmd-label"? This is because docker. Should I open new thread? I think it will be complicated to understand others what is going on still they won't see this conversation. Do you know how to fix it?
    – pushandpop
    Jan 16, 2015 at 15:25
  • This is indeed probably a separate problem. Jan 16, 2015 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .