Stop all the containers (docker stop <containerId>
) you don't need anymore and run those two commands:
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)
The first command will delete all inactive containers (the others will pop up errors, but they can be ignored).
The second command removes all images that are not used by any container (also the non actives).
Note: The next time you start a container you have to download all the layers again.
As Mark O'Connor pointed out there is also the -v
option to remove associated volumes. Make sure you don't loose any important data with that!
docker rm -v $(docker ps -a -q)
From the Docker rm docs:
-f, --force=false Force the removal of a running container (uses SIGKILL)
-l, --link=false Remove the specified link
-v, --volumes=false Remove the volumes associated with the container