While testing our PMM2 Beta and other Dockerized applications, you may want to clean up your docker install and start from scratch. If you’re not very familiar with Docker it may not be that trivial. This post focuses on cleaning up everything in docker so you can “start from scratch” which means removing all your containers and their data. Make sure this is what you really want!
First, you have running (and stopped containers):
1 2 3 4 |
root@pmm2-test:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 810fef9a2a05 perconalab/pmm-server:2.0.0-beta5 "/opt/entrypoint.sh" 2 weeks ago Up 2 weeks 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp pmm-server-2.0.0-beta5 7e2595b2b7ad perconalab/pmm-server:2.0.0-beta5 "/bin/true" 2 weeks ago Created pmm-data-2-0-0-beta5 |
Which you can stop and remove.
1 2 3 4 5 |
root@pmm2-test:~# docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q) 810fef9a2a05 7e2595b2b7ad 810fef9a2a05 7e2595b2b7ad |
You may feel like you are done at this point, but not really. You may have a lot of disk space held up in other Docker objects:
1 2 3 4 5 6 |
root@pmm2-test:~# docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 1 0 1.331GB 1.331GB (100%) Containers 0 0 0B 0B Local Volumes 1 0 52.61GB 52.61GB (100%) Build Cache 0 0 0B 0B |
Now we can see that we have about 1GB still held up in images and the larger amount of 52GB in local volumes. To clean these up, we want to see their names, which you can do with the same “df” command:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
root@pmm2-test:~# docker system df -v Images space usage: REPOSITORY TAG IMAGE ID CREATED SIZE SHARED SIZE UNIQUE SIZE CONTAINERS perconalab/pmm-server 2.0.0-beta5 9b3111808907 2 weeks ago 1.331GB 0B 1.331GB 0 Containers space usage: CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED STATUS NAMES Local Volumes space usage: VOLUME NAME LINKS SIZE a3e9e89f3c43bdaa817e014d08e73705562a9affe4dae54817d77a1b8ad0c771 0 52.61GB Build cache usage: 0B CACHE ID CACHE TYPE SIZE CREATED LAST USED USAGE SHARED |
From here you can, of course, remove volumes and images one by one, but you may choose to do this instead:
Remove All Docker Images:
1 2 3 4 5 6 7 8 9 |
root@pmm2-test:~# docker image prune -a -f Deleted Images: untagged: perconalab/pmm-server:2.0.0-beta5 untagged: perconalab/pmm-server@sha256:55968571b01e1f2b02cee77ef92afa05f93c1a0b8e506ceebc10d03bff9783be deleted: sha256:9b3111808907a3cd02d4961b114471c8ec16dc0dc430cfd8c4a4f556804e57ec deleted: sha256:4cb3b12fc91c29837374de51f6279d911c9e21d73d22a009841ac9a00e6a7e96 deleted: sha256:d69483a6face4499acb974449d1303591fcbb5cdce5420f36f8a6607bda11854 Total reclaimed space: 1.331GB |
And Remove all Docker Local Volumes:
1 2 3 4 5 |
root@pmm2-test:~# docker system prune --volumes -f Deleted Volumes: a3e9e89f3c43bdaa817e014d08e73705562a9affe4dae54817d77a1b8ad0c771 Total reclaimed space: 52.61GB |
We can run “docker system df” again to see if we really cleaned up everything or if anything else remains:
1 2 3 4 5 6 |
root@pmm2-test:~# docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 0 0 0B 0B Containers 0 0 0B 0B Local Volumes 0 0 0B 0B Build Cache 0 0 0B 0B |
All clear. We can now have a fresh start with docker!
Leave a Reply