GithubHelp home page GithubHelp logo

zzrotdesign / docker-clean Goto Github PK

View Code? Open in Web Editor NEW
1.3K 34.0 92.0 8.78 MB

A script that cleans docker containers, images, volumes, and networks.

License: MIT License

Shell 97.18% Groff 0.29% Makefile 2.54%
docker docker-clean golang shell

docker-clean's People

Contributors

caiofbpa avatar gitter-badger avatar killianbrackey avatar kilpatty avatar withinboredom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-clean's Issues

Full Linux support

Incorporate docker service restart and other checks to make fully linux compatible for apt-get, yum, apk, etc.

Linux support please!

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.

1. What version of Docker-Clean are you running (docker-clean --version)?

2. What command are you trying to run?

3. What did you expect to see?

4. What did you see instead ( 'docker-clean -l or --verbose' for the entire log )?

5. What are your system specs?

Docker Version:
Docker-Machine Version:
OS/Version:

Containers to delete array doesn't always update

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.

1. What version of Docker-Clean are you running (docker-clean --version)?

2.0.4

2. What command are you trying to run?

docker-clean all

3. What did you expect to see?

$ 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

4. What did you see instead ( 'docker-clean -l or --verbose' for the entire log )?

$ 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

5. What are your system specs?

OSX Capitan, Bash 4.x

Docker Version: Docker for mac beta
Docker-Machine Version: N/A

Add support for Dead containers

Dead containers are not currently being recognized as stopped containers.

This logic should get built in as another optional flag.

Cross platform daemon restart

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!

Clean Networks

Since networks also need to be cleaned it would be good to add this as an option as well.

Add a 'dry-run' mode

It would be very helpful to see everything that WOULD be deleted first without actually deleting it all

flag provided but not defined: -f

1. What version of Docker-Clean are you running (docker-clean --version)?

docker-clean: 2.0.1

2. What command are you trying to run?

docker-clean

3. What did you expect to see?

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

4. What did you see instead ( 'docker-clean -l or --verbose' for the entire log )?

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

5. What are your system specs?

Docker Version: 1.9.1
Docker-Machine Version: docker-machine version 0.5.1 (7e8e38e)
OS/Version: OS X 10.11.4 (El Capitan)

docker-clean is not removing "Created" containers

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.

1. What version of Docker-Clean are you running (docker-clean --version)?

2.0.4

2. What command are you trying to run?

docker-clean

3. What did you expect to see?

Created containers like this get deleted:

c40b50fd725e        c0c490b65679                                                "/bin/sh -c '#(nop) V"   24 hours ago        Created                                                                    distracted_bell

4. What did you see instead ( 'docker-clean -l or --verbose' for the entire log )?

$ 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

5. What are your system specs?

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 ; }

Used networks will be removed

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

1. What version of Docker-Clean are you running ( docker-clean --version)?

2.0.4

2. What command are you trying to run?

docker-clean

Docker Version: 18.02
Docker-Machine Version: docker-machine version 0.13.0, build 9ba6da9
OS/Version: MacOS 10.13.3 (17D47)

errors with 'docker-clean all' command

1. What version of Docker-Clean are you running ?

2.0.4

2. What command are you trying to run?

docker-clean all

4. What did you see instead ( 'docker-clean -l or --verbose' for the entire log )?

~# 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!

5. What are your system specs?

Docker Version: 1.11.2, build b9f10c9
OS/Version: Ubuntu 14.04

Better Docker for Mac support

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  :

Image size

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

1. What version of Docker-Clean are you running ( docker-clean --version)?

2.0.4

5. What are your system specs?

OS/Version:
Description: Ubuntu 16.04.1 LTS
Release: 16.04
Codename: xenial

'docker-clean stop' is clearing images

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.

1. What version of Docker-Clean are you running ( docker-clean --version)?

v2.0.4

2. What command are you trying to run?

stop

3. What did you expect to see?

Not images being cleared

4. What did you see instead ( 'docker-clean -l or --verbose' for the entire log )?

Images being cleared

5. What are your system specs?

Docker Version:
Docker-Machine Version:
OS/Version: Linux

Cannot run docker-clean using docker as per instructions

1. What version of Docker-Clean are you running ( docker-clean --version)?

latest docker image tag (id: 91b2e956f1b4, created 3 weeks ago)

2. What command are you trying to run?

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

3. What did you expect to see?

No Images to delete!
No dangling volumes!
No empty networks!

4. What did you see instead ( 'docker-clean -l or --verbose' for the entire log )?

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

5. What are your system specs?

Docker Version: 1.12.5
Docker-Machine Version: N/A
OS/Version: Ubuntu 16.04

Add Created Containers Flag

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.

Count Number of Deleted Images

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.

Delete based on regexp

Implement a regexp to run more aggressive cleanup tasks on known images/containers that may still be tagged

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.