Skip to content

Remove all the docker images except the N most recently pulled

License

Notifications You must be signed in to change notification settings

aebm/docker-image-cleaner

Repository files navigation

docker-image-cleaner Build Status

From all the pulled docker images remove keep only the N most recent images pulled

Installation

  • Clone repo

  • It is adviced to use a virtualenv

  • To setup a virtualenv

    $ virtualenv --clear --always-copy VIRTUALENV_NAME
  • Install dependencies

    $ VIRTUALENV_NAME/bin/pip install -r requirements.txt
  • Run it with the same privileges as the docker client

    $ VIRTUALENV_NAME/bin/python di_cleaner.py --help
  • Another way

    $ source VIRTUALENV_NAME/bin/activate
    $ ./di_cleaner --help

Examples

  • Run and show what images it is going to delete without deleting them

    $ VIRTUALENV_NAME/bin/python di_cleaner.py --verbose --noop
  • Run with debug on

    $ VIRTUALENV_NAME/bin/python di_cleaner.py --debug
  • Delete all images except the 10 most recent ones

    $ VIRTUALENV_NAME/bin/python di_cleaner.py --images-to-keep 10
  • If you want to preserve the <none> images

    $ VIRTUALENV_NAME/bin/python di_cleaner.py --keep-none-images

Mac OSX

Start up your docker-machine. You need to setup the environment of your docker-machine in your shell

$ eval "$(docker-machine env default)"

Note, default is your virtual machine name

Now you can run all examples.

Tests

Run

$ VIRTUALENV_NAME/bin/python -m unittest discover

Use docker image

Build the image as ${IMAGE_NAME}

docker build  -t ${IMAGE_NAME} .

Execute the program connected to the host socket

docker run -v /var/run/docker.sock:/var/run/docker.sock --rm -it ${IMAGE_NAME} --help

About

Remove all the docker images except the N most recently pulled

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •