How to stop and remove a docker container?

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.


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