Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I clean up my docker host machine

Tags:

docker

coreos

As I create/debug a docker image/container docker seems to be leaving all sorts of artifacts on my system. (at one point there was a 48 image limit) But the last time I looked there were 20-25 images; docker images.

So the overarching questions are:

  • how does one properly cleanup?
  • as I was manually deleting images more started to arrive. huh?
  • how much disk space should I really allocate to the host?
  • will running daemons really restart after the next reboot?

and the meta question... what questions have I not asked that need to be?

like image 203
Richard Avatar asked Apr 21 '14 00:04

Richard


People also ask

What is the best way to clean up storage generated by docker containers on a host machine?

How to cleanup docker containers? docker container rm has two useful options: -v or --volumes which will remove volumes associated with the container being removed. -f or --force which will force the removal of the container with SIGKILL.

How do I get rid of unused docker volumes?

Volumes are removed using the docker volume rm command. You can also use the docker volume prune command.


2 Answers

Here's how I periodically purge my docker host:

Kill running containers:

docker kill $(docker ps -qa) 

Delete all containers (and their associated volumes):

docker rm -v $(docker ps -qa) 

Remove all images:

docker rmi $(docker images -q) 

Update

Delete only the containers that are not running. Parse the "ps" output for the "Exited" string:

docker ps -a | awk '/Exited/ {print $1}' | xargs docker rm -v 

Not perfect... Don't give your container the name "Exited" :-)

Update

Docker 1.9 has a new volume command that can be used to purge old volumes

docker volume rm $(docker volume ls -qf dangling=true) 

Update

Latest community edition of docker has a new "system prune" command

docker system prune --volumes 

This purged unused networks, kill stopped containers, dangling images and any unused volumes.

like image 75
Mark O'Connor Avatar answered Sep 29 '22 17:09

Mark O'Connor


It can also be helpful to remove "dangling" images

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

like image 20
user2363318 Avatar answered Sep 29 '22 16:09

user2363318