Saturday, May 18, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  12] [ 0]  / answers: 1 / hits: 43339  / 2 Years ago, tue, november 15, 2022, 6:52:05

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?


More From » bash

 Answers
5

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.


[#21680] Wednesday, November 16, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bewre

Total Points: 164
Total Questions: 108
Total Answers: 106

Location: Ghana
Member since Sun, Mar 27, 2022
2 Years ago
;