I installed docker on a Debian 7 machine in the following way
$ echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list
$
If it's just a test installation of Docker (ie not production) and you don't care about doing a nuclear clean, you can:
clean all containers:
docker ps -a | sed '1 d' | awk '{print $1}' | xargs -L1 docker rm
clean all images:
docker images -a | sed '1 d' | awk '{print $3}' | xargs -L1 docker rmi -f
Again, I use this in my ec2 instances when developing Docker, not in any serious QA or Production path. The great thing is that if you have your Dockerfile(s), it's easy to rebuild and or docker pull
.
As already mentioned,
docker system prune
helps, but with Docker 17.06.1 and later without pruning unused volumes. Since Docker 17.06.1, the following command prunes volumes, too:
docker system prune --volumes
From the Docker documentation: https://docs.docker.com/config/pruning/
The docker system prune command is a shortcut that prunes images, containers, and networks. In Docker 17.06.0 and earlier, volumes are also pruned. In Docker 17.06.1 and higher, you must specify the --volumes flag for docker system prune to prune volumes.
If you want to prune volumes and keep images and containers:
docker volume prune
I run the below commands.
There is no need to rebuilt images afterwards.
docker rm $(docker ps -qf 'status=exited')
docker rmi $(docker images -qf "dangling=true")
docker volume rm $(docker volume ls -qf dangling=true)
These remove exited/dangling containers and dangling volumes.
$ docker rm $(docker ps -aq)
This worked for me
docker system prune
appears to be better option with latest version
I just ran into this. I'm on Ubuntu 20.04. What worked? Reinstalling Docker:
sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo apt-get install docker-ce docker-ce-cli containerd.io
A bit crude, I know. I tried pruning Docker, but it still would not work.
docker rmi $(docker images -f "dangling=true" -q)