zzrotdesign / docker-clean Goto Github PK
View Code? Open in Web Editor NEWA script that cleans docker containers, images, volumes, and networks.
License: MIT License
A script that cleans docker containers, images, volumes, and networks.
License: MIT License
Results in errors saying that container or image doesn't exist. Suspect an array not being re-assigned.
It would be useful to have a flag in order to remove anonymous volumes.
Incorporate docker service restart and other checks to make fully linux compatible for apt-get, yum, apk, etc.
If you are filing a bug report, please answer these questions. If your issue is not a bug report, you do not need to use this template.
docker-clean --version
)?Docker Version:
Docker-Machine Version:
OS/Version:
If you are filing a bug report, please answer these questions. If your issue is not a bug report, you do not need to use this template.
docker-clean --version
)?2.0.4
docker-clean all
$ docker-clean all
Stopping running containers...
Containers stopped: 1
Cleaning containers...
Stopped containers cleaned: 1
Cleaning images...
Images cleaned: 6
You've cleared approximately MB: 294 of space!
Cleaning existing dangling volumes...
Volumes cleaned: 3
Removing empty networks...
Networks removed: 2
$ docker-clean all
Stopping running containers...
Containers stopped: 1
Cleaning containers...
Stopped containers cleaned: 1
Cleaning images...
Error: No such image or container: 2a3ec64a853f
Error: No such image or container: 2a3ec64a853f
Error: No such image or container: 0c8cc95b92ee
Error: No such image or container: 0c8cc95b92ee
Images cleaned: 6
You've cleared approximately MB: 294 of space!
Cleaning existing dangling volumes...
Volumes cleaned: 3
Removing empty networks...
Networks removed: 2
OSX Capitan, Bash 4.x
Docker Version: Docker for mac beta
Docker-Machine Version: N/A
Dead containers are not currently being recognized as stopped containers.
This logic should get built in as another optional flag.
Update makefile to run on tagged releases to make the image names make the more logical sense.
Currently we are just checking uname
for Darwin, Linux, or MING32_NT. Restart works for Darwin and MING32_NT. However we are only running sudo docker service
restart (works on Upstart). This will not work with platforms with init systems other than Upstart:
systemd systemctl start docker.service
SysV /etc/init.d/docker start
OpenRC /etc/init.d/docker start
rc launchctl start docker
.
Any help or suggestions on checking for this are appreciated!
Since networks also need to be cleaned it would be good to add this as an option as well.
It would be very helpful to see everything that WOULD be deleted first without actually deleting it all
docker-clean --version
)?docker-clean: 2.0.1
docker-clean
Cleaning images...
Images cleaned: 11
You've cleared approximately MB: 220 of space!
Cleaning existing dangling volumes...
Volumes cleaned: 13
Removing empty networks...
Networks removed: 3
flag provided but not defined: -f
See 'docker network inspect --help'.
flag provided but not defined: -f
flag provided but not defined: -f
See 'docker network inspect --help'.
flag provided but not defined: -f
flag provided but not defined: -f
See 'docker network inspect --help'.
flag provided but not defined: -f
flag provided but not defined: -f
See 'docker network inspect --help'.
flag provided but not defined: -f
flag provided but not defined: -f
See 'docker network inspect --help'.
flag provided but not defined: -f
flag provided but not defined: -f
See 'docker network inspect --help'.
flag provided but not defined: -f
Cleaning images...
Images cleaned: 11
You've cleared approximately MB: 220 of space!
Cleaning existing dangling volumes...
Volumes cleaned: 13
Removing empty networks...
Networks removed: 3
Docker Version: 1.9.1
Docker-Machine Version: docker-machine version 0.5.1 (7e8e38e)
OS/Version: OS X 10.11.4 (El Capitan)
If you are filing a bug report, please answer these questions. If your issue is not a bug report, you do not need to use this template.
docker-clean --version
)?2.0.4
docker-clean
Created containers like this get deleted:
c40b50fd725e c0c490b65679 "/bin/sh -c '#(nop) V" 24 hours ago Created distracted_bell
$ docker-clean -l
Cleaning images...
DELETED: REPOSITORY/TAG: [] IMAGE ID: afa91711ce87
Images cleaned: 1
You've cleared approximately MB: 726 of space!
No dangling volumes!
Removing empty networks...
Error response from daemon: network 2a52733d35db 1099cf15fad1 d643b953957e 8e5cd7ac7807 eaeb7e2b7710 not found
Networks removed: 1
Docker Version: 1.11.2 server (Ubuntu 14.04.4 LTS, 3.13.0-85-generic, aufs)
Docker client: 1.11.1
Docker-Machine Version: n/a
OS/Version: OSX
Using this as a workaround:
function dclean() { docker ps -q -a -f status=exited | xargs -n 100 docker rm -v ; docker ps -q -a -f status=created | xargs -n 100 docker rm -v ; docker images -q --filter "dangling=true" | xargs -n 100 docker rmi ; }
After the command docker-clean
all networks will be removes and can not recreated with docker-compose up
ERROR: for npm Cannot start service npm: network 78b26a199b847c71bc483c81ebd05236ce241486f0605671fe5d29c824d20ad7 not found
ERROR: for redis Cannot start service redis: network 78b26a199b847c71bc483c81ebd05236ce241486f0605671fe5d29c824d20ad7 not found
docker-clean --version
)?2.0.4
docker-clean
Docker Version: 18.02
Docker-Machine Version: docker-machine version 0.13.0, build 9ba6da9
OS/Version: MacOS 10.13.3 (17D47)
2.0.4
docker-clean all
~# docker-clean -l all
No running containers!
Cleaning containers...
Error response from daemon: devmapper: Unknown device 4a96badceaf94c204d9248cb594b9ba316d7a1cef899ab4637e8f6e7259e1b09
Error response from daemon: devmapper: Unknown device 4a96badceaf94c204d9248cb594b9ba316d7a1cef899ab4637e8f6e7259e1b09
Error response from daemon: devmapper: Unknown device 4a96badceaf94c204d9248cb594b9ba316d7a1cef899ab4637e8f6e7259e1b09
DELETED: ID: f2d4ef3216a8 IMAGE: / NAME:
Stopped containers cleaned: 1
Cleaning images...
DELETED: REPOSITORY/TAG: [] IMAGE ID: 8ec602c0ee99
Error: No such image or container: 99b7073596fb
Error: No such image or container: 99b7073596fb
Error: No such image or container: c4b4bf8f23fb
Error: No such image or container: c4b4bf8f23fb
DELETED: REPOSITORY/TAG: ["node:argon"] IMAGE ID: 1f9967dbfc82
DELETED: REPOSITORY/TAG: ["mysql:5.7"] IMAGE ID: 2fd136002c22
Images cleaned: 3
You've cleared approximately MB: 1672 or GB: 1 of space!
No dangling volumes!
No empty networks!
Docker Version: 1.11.2, build b9f10c9
OS/Version: Ubuntu 14.04
Docker for Mac is not necessarily working like Docker Machine. Currently, you get a sort of an error:
$ docker-clean -r
No active host found
Host does not exist: ""
Host does not exist: ""
Running docker-machine env ...
Error: No machine name(s) specified and no "default" machine exists
New IP Address for :
Hey guys,
Really appreciated your work! I was curious to find that this image size is that big. Have your tried FROM alpine:3.4 ?
zzrot/docker-clean latest 26c88e88101d 12 weeks ago 108.3 MB
docker-clean --version
)?2.0.4
OS/Version:
Description: Ubuntu 16.04.1 LTS
Release: 16.04
Codename: xenial
I have a use case where in development I want to keep running, exited and created containers, and only remove images that are not used by them.
Apologies for not knowing bash well enough to make a PR.
Hi,
Could you outline in README, how is this docker image better than docker system prune or just wiping the /var/lib/docker directory? I was suggested this project and maybe it solves a problem, that I did not know, that I had ๐
Perhaps this is just a documentation clarification, but with the "stop" command, I was not expecting images to be cleared.
Example output:
$ docker-clean stop
No running containers!
Cleaning containers...
Stopped containers cleaned: 2
Cleaning images...
Images cleaned: 1
You've cleared approximately MB: 1506 or GB: 1 of space!
Cleaning existing dangling volumes...
Volumes cleaned: 2
No empty networks!
If you are filing a bug report, please answer these questions. If your issue is not a bug report, you do not need to use this template.
docker-clean --version
)?v2.0.4
stop
Not images being cleared
Images being cleared
Docker Version:
Docker-Machine Version:
OS/Version: Linux
docker-clean --version
)?latest
docker image tag (id: 91b2e956f1b4, created 3 weeks ago)
From a newly installed docker instance on a "clean" VM: docker run --rm -v /var/run/docker.sock:/var/run/docker.sock zzrot/docker-clean
No Images to delete!
No dangling volumes!
No empty networks!
docker: Error response from daemon: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused "exec: \"/docker-clean/docker-clean\": stat /docker-clean/docker-clean: no such file or directory
Docker Version: 1.12.5
Docker-Machine Version: N/A
OS/Version: Ubuntu 16.04
Currently, this is the what the tool outputs:
You've cleared approximately MB: 1292 or GB: 1 of space!
It is not proper English even and even less so - SI. It should be instead:
You've cleared approximately 1,292 MB or 1 GB of space!
And, yes, there should be a space after the number: https://www.engadget.com/2010/12/16/32-gb-versus-32gb-almost-everyone-is-writing-it-wrong/
Add option to exclude container names and/or image names
We need to add a flag to allow people who want to keep created containers as there are some instances were created containers should not be treated as exited containers.
Add functionality to output the number of containers, images, volumes deleted. Additionally block that massive amount of output (the deleted image hashs) from user's stdout.
Implement a regexp to run more aggressive cleanup tasks on known images/containers that may still be tagged
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.