Docker is commonly used for packaging and shipping softwares. Developers who use docker frequently, often face the issue of disk running low due to docker taking up a lot of space in the shape of docker images, containers, volumes etc.
This utility was created to help developers clean up docker resources that are no longer required. Currently, only images and containers are supported.
Install the utility by running the following command:
pip3 install dockclean
> dockclean --help
Usage: dockclean [OPTIONS] COMMAND [ARGS]...
This tool provides commands to remove unwanted docker images and
containers
Options:
--help Show this message and exit.
Commands:
containers Removes unwanted containers.
images Removes unwanted images.
You can view the usage of the subcommands by simply adding the --help
flag.
The images
subcommand by default only removes the dangling images.
dockclean images
The following command removes all the the images which have names starting with python
:
dockclean images --pattern "^python.*"
The following command removes all the images belonging to the repository amazon
:
dockclean images --repository "amazon"
Note: repository here represents the text before the first
/
in the image name. For e.g for imageamazon/aws-cli:2.9.17
, the repository isamazon
.
To exclude images to be removed, simply use the --exclude
or -e
flag. The --exclude
similar to --pattern
flag expects a regex pattern. Any image matching this pattern won't be deleted.
dockclean images --pattern "^python.*" --exclude ".*3.10-slim.*"
The above command would remove all the images with name starting with python
except for those who have 3.10-slim
text in them.
The containers
subcommand by default removes only stopped/exited containers.
dockclean containers
The following command remove all containers whether running or stopped:
dockclean containers --remove_all
For running the project locally, it is recommended to create a python virtual environment first:
-
Ensure that the following are installed:
a. python3 (Installed based on your distro)
b. pip3 (
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3 get-pip.py
)c. virtualenv
-
Open up a terminal
-
Create a directory somewhere
mkdir dockclean-env
andcd
into it -
Create a python virtual environment
python3 -m virtualenv .
-
Activate the virtual environment
source bin/activate
-
Navigate to the projects root directory where
setup.py
file is located
Now install and run dockclean:
-
Do a
pip install .
. -
Run the
dockclean
.
I've just started out with this project and there is a lot to be added. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Please support the project by giving it a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request