Manage Docker environments by cleaning up unused or outdated resources.
10K+
A flexible, safe, and automated CLI for cleaning unused Docker containers, images, volumes, and networks.
docker-prune is a powerful and flexible CLI tool for managing and cleaning up unused Docker resources — including containers, images, volumes, and networks. Unlike basic docker system prune, this tool allows you to define complex, fine‑grained cleanup rules via filters, labels, regex patterns, and YAML configuration files.
This makes it ideal for:
With semantic versioned Docker images, built‑in cleanup profiles, and a cron‑based scheduler, docker-prune can run fully automated in the background, tailored to your needs — all inside a rootless container for improved security.
bridge, host, none) and custom exclusions.app) with configurable UID/GID for enhanced security.To install the docker-prune binary, run:
pip install docker-prune
This will make the docker-prune command available in your system's PATH.
In addition to installing via pip, you can run docker-prune directly from its published Docker image. Images are available from:
ghcr.io/t4skforce/docker-prunet4skforce/docker-pruneSecurity: Runs as rootless
appuser by default (UID=1000,GID=967) for improved security.
docker pull ghcr.io/t4skforce/docker-prune:latest
docker pull t4skforce/docker-prune:latest
The images follow Semantic Versioning (SemVer) and multiple tags are published for each release:
| Tag example | Description |
|---|---|
latest | Always points to the latest stable release |
v1.0.4 | Full SemVer – pinned to an exact release |
v1.0 | Minor version – receives updates for all v1.0.x releases |
v1 | Major version – receives updates for all v1.x.x releases |
This allows you to:
latestv1v1.0v1.0.4Examples:
# Always get latest v1.x.x release
docker pull ghcr.io/t4skforce/docker-prune:v1
# Pin to a specific version
docker pull t4skforce/docker-prune:v1.0.4
Run docker-prune from the container:
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
ghcr.io/t4skforce/docker-prune:latest --help
Run with a specific profile and schedule:
docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DOCKER_PRUNE_PROFILE=aggressive \
-e DOCKER_PRUNE_SCHEDULE="0 */6 * * *" \
t4skforce/docker-prune:v1
Run with a custom configuration file:
docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /path/to/config.yml:/config/config.yml \
-e DOCKER_PRUNE_CONFIG_FILE=/config/config.yml \
ghcr.io/t4skforce/docker-prune:v1.0.4
You can also run docker-prune as a scheduled cleanup service using Docker Compose.
This is ideal for homelab or server environments where you want regular automated pruning without manual runs.
Example: daily cleanup at 3 AM using the default profile
version: "3.8"
services:
docker-prune:
image: ghcr.io/t4skforce/docker-prune:v1
container_name: docker-prune
restart: unless-stopped
environment:
# Choose one of: default, aggressive, conservative
DOCKER_PRUNE_PROFILE: default
# Optional: change the schedule (default is 0 2 * * *)
DOCKER_PRUNE_SCHEDULE: "0 3 * * *"
# Optional: set timezone
TZ: Europe/Berlin
volumes:
# Mount Docker socket to control Docker on the host
- /var/run/docker.sock:/var/run/docker.sock:ro
read_only: true
tmpfs:
- /tmp:rw,noexec,nosuid,size=1024
- /home/app/.docker:rw,noexec,nosuid,size=1024
security_opt:
- no-new-privileges:true
network_mode: none
Example: aggressive cleanup every 6 hours
version: "3.8"
services:
docker-prune:
image: ghcr.io/t4skforce/docker-prune:v1
restart: unless-stopped
environment:
DOCKER_PRUNE_PROFILE: aggressive
DOCKER_PRUNE_SCHEDULE: "0 */6 * * *"
TZ: UTC
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
read_only: true
tmpfs:
- /tmp:rw,noexec,nosuid,size=1024
- /home/app/.docker:rw,noexec,nosuid,size=1024
security_opt:
- no-new-privileges:true
network_mode: none
Deploy:
docker compose up -d
Check logs:
docker compose logs -f docker-prune
docker-prune info
Displays storage usage information for Docker images and volumes.
Example Output:
INFO - Overall usage Images: 732.91MB Volumes: 1.31MB
INFO - Total reclaimed space: 0.00B
docker-prune run cleanup-config.yml
Runs cleanup commands from a YAML configuration file.
Additional options:
--validate: Validate the configuration file and exit without running any commands.--exit / --no-exit: Exit immediately if a command exits with a non-zero status (default: --no-exit).The docker-prune containers command group lets you stop running containers or remove stopped containers using multiple filters.
All filters are combined with AND logic — only containers matching all specified filters are affected.
Notes:
stop command affects running containers.rm command affects stopped containers only.--not-* filters are useful for protecting important containers from cleanup runs.docker-prune containers stop stops running containers that match your criteria.
Defaults:
--restart: 100 (stop containers restarted more than 100 times by default)--not-label: Excludes containers with labels matching:
^(com.docker|io.podman).keep=(1|true|yes)?$Examples:
# Stop containers older than 1 week
docker-prune containers stop --age "1w"
# Stop containers with more than 50 restarts
docker-prune containers stop --restart 50
# Stop containers named like 'test-*' except those with 'keep' in the name
docker-prune containers stop --name "^test-.*" --not-name "keep"
docker-prune containers rm removes stopped containers that match your criteria.
Supported filters:
--age / -a: Remove stopped containers older than the given age (default: 1w).--name: Include only containers with names matching a regex.--not-name: Exclude containers with names matching a regex.--label: Include only containers with labels matching a regex.--not-label: Exclude containers with labels matching a regex.
Default exclusions:
^(com.docker|io.podman).keep=(1|true|yes)?$Examples:
# Remove stopped containers older than 2 weeks
docker-prune containers rm --age "2w"
# Remove stopped containers with label 'env=dev'
docker-prune containers rm --label "^env=dev$"
# Remove stopped containers with 'temp' in their name, except those with label 'keep=true'
docker-prune containers rm --name "temp" --not-label "^keep=true$"
The docker-prune images command removes unused Docker images according to the filters you specify, and also performs additional automatic cleanup to reclaim disk space.
By default, it will:
Remove images matching your filters, such as:
--age: Remove images older than the given age (default: 90d)--tag / --not-tag: Include or exclude images by tag regex--label / --not-label: Include or exclude images by label regexPrune dangling images (untagged images that are not used by any container).
Prune the Docker build cache, optionally keeping a certain amount of build cache space using --keep-builds.
Examples:
Remove images older than 90 days (default):
docker-prune images --age "90d"
Remove images older than 30 days but exclude the latest tag:
docker-prune images --age "30d" --not-tag "^latest$"
Remove all unused images and keep only 500MB of build cache:
docker-prune images --keep-builds 500MB
The docker-prune volumes command removes unused Docker volumes based on filters you specify.
By default, it:
Default --not-label exclusions:
^(com.docker|io.podman).compose.(project|volume)^(com.docker|io.podman).keep=(1|true|yes)?$Examples:
Remove dangling volumes older than 30 days (default):
docker-prune volumes
Remove dangling volumes older than 7 days:
docker-prune volumes --age "7d"
Remove volumes with names starting with temp_:
docker-prune volumes --name "^temp_"
Remove volumes except those matching important in the name:
docker-prune volumes --not-name "important"
Remove all unused volumes, ignoring default label exclusions:
docker-prune volumes --not-label ""
The docker-prune networks command removes unused custom Docker networks based on filters you specify.
By default, it:
bridge, host, none) automatically.Examples:
Remove unused custom networks older than 15 days:
docker-prune networks --age "15d"
Remove unused networks with names starting with temp_:
docker-prune networks --name "^temp_"
Remove unused networks except those matching important in the name:
docker-prune networks --not-name "important"
Remove all unused networks, ignoring default label exclusions:
docker-prune networks --not-label ""
Note:
bridge, host, none) are always excluded from pruning and cannot be included.--not-label option excludes networks commonly associated with docker-compose or Podman projects, such as:
^(com.docker|io.podman).compose.(project|network)^(com.docker|io.podman).keep=(1|true|yes)?$Enable detailed logging for debugging:
docker-prune --debug containers stop --age "2d"
You can specify cleanup rules in a YAML file:
- docker-prune containers stop --age "7d"
- docker-prune containers rm --age "30d"
- docker-prune images --age "90d" --not-tag "^latest$"
- docker-prune volumes --age "30d" --not-label "^com.docker.compose.project"
- docker-prune networks --age "15d"
Run the configuration:
docker-prune run config.yml
docker-prune comes with several built‑in cleanup profiles — pre‑defined YAML configuration files (config-*.yaml) baked into the container image.
These let you run cleanup tasks without writing your own config from scratch.
You can select a profile using the DOCKER_PRUNE_PROFILE environment variable, or override it entirely with a custom config via DOCKER_PRUNE_CONFIG_FILE.
| Profile | Purpose |
|---|---|
| default | Balanced cleanup — safe for most environments. (see. config-default.yml) |
| aggressive | Faster and more frequent cleanup — best when disk space is critical. (see. config-aggressive.yml) |
| conservative | Minimal cleanup — prioritizes safety, good for production. (see. config-conservative.yml) |
| act | Optimized for self‑hosted GitHub Actions runners using nektos/act. Cleans up aggressively between CI jobs to free space, while keeping commonly reused CI images cached to minimize registry pulls and speed up builds. (see. config-act.yml) |
The Docker container for docker-prune starts a cronjob scheduler by default. The cleanup tasks are executed based on the selected profile (default, aggressive, conservative, act) and are scheduled to run at 0 2 * * * (every day at 2:00 AM). Profiles act as shorthand for built-in configuration files, but users can provide a fully custom configuration file if needed.
DOCKER_PRUNE_PROFILE:
default, aggressive, conservative, act).-e DOCKER_PRUNE_PROFILE=aggressive
DOCKER_PRUNE_CONFIG_FILE:
-e DOCKER_PRUNE_CONFIG_FILE=/path/to/custom-config.yaml
DOCKER_PRUNE_SCHEDULE:
-e DOCKER_PRUNE_SCHEDULE="*/10 * * * *" # Runs every 10 minutes
Since docker-prune uses the Python Docker SDK, you can configure how it connects to the Docker daemon using the standard environment variables supported by the SDK.
If not set, the SDK defaults to:
/var/run/docker.sock on Linux/macOS//./pipe/docker_engine on WindowsYou can override this behavior using:
| Variable | Description | Example |
|---|---|---|
DOCKER_HOST | URL to the Docker host. Use unix:///var/run/docker.sock for local or tcp://host:port for remote. | tcp://192.168.1.50:2376 |
DOCKER_TLS_VERIFY | Set to 1 to enable TLS verification. | 1 |
DOCKER_CERT_PATH | Path to the directory containing TLS certificates (ca.pem, cert.pem, key.pem). Required if DOCKER_TLS_VERIFY=1. | /home/app/.docker |
DOCKER_CONFIG | Path to the Docker CLI config directory (used for authentication, etc.). | /home/app/.docker |
Example – connect to a remote Docker host with TLS:
export DOCKER_HOST=tcp://192.168.1.50:2376
export DOCKER_TLS_VERIFY=1
export DOCKER_CERT_PATH=$HOME/.docker/certs
docker-prune info
Example – run container with remote Docker host:
docker run -it \
-e DOCKER_HOST=tcp://192.168.1.50:2376 \
-e DOCKER_TLS_VERIFY=1 \
-e DOCKER_CERT_PATH=/certs \
-v /path/to/certs:/certs:ro \
ghcr.io/t4skforce/docker-prune:latest info
For more details, see the Docker SDK for Python documentation on environment variables.
docker run -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DOCKER_PRUNE_PROFILE=aggressive \
-e DOCKER_PRUNE_SCHEDULE="0 */6 * * *" \
-e TZ=Europe/Berlin \
docker-prune:latest
docker run -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DOCKER_PRUNE_CONFIG_FILE=/path/to/custom-config.yaml \
-e DOCKER_PRUNE_SCHEDULE="0 */6 * * *" \
-e TZ=Europe/Berlin \
docker-prune:latest
The DOCKER_PRUNE_SCHEDULE environment variable uses cron-style expressions for scheduling cleanup tasks. Below are a few examples:
| Schedule | Description |
|---|---|
0 2 * * * | Every day at 2:00 AM (default). |
*/10 * * * * | Every 10 minutes. |
0 */6 * * * | Every 6 hours. |
0 3 * * 1 | Every Monday at 3:00 AM. |
30 1 1 * * | On the first day of every month at 1:30 AM. |
For more advanced scheduling options, refer to the Supercronic documentation.
Many commands come with default values for parameters. Below are some commonly used defaults:
Containers:
--age: 1w (1 week) for rm command--timeout: 60 (60 seconds before forcing stop)--restart: 100 (only for stop command)--not-label: By default, both stop and rm exclude containers with labels:
^(com.docker|io.podman).keep=(1|true|yes)?$Images:
--age: 90d (90 days)Volumes:
--age: 30d (30 days)--not-label: Excludes common docker-compose and Podman volume labels, plus keep-labels:
^(com.docker|io.podman).compose.(project|volume)^(com.docker|io.podman).keep=(1|true|yes)?$Networks:
--age: None (manual configuration required)--not-name: Excludes bridge, host, none.--not-label: By default excludes common Docker Compose / Podman network labels and keep-labels.
^(com.docker|io.podman).compose.(project|network)^(com.docker|io.podman).keep=(1|true|yes)?$Clone the repository:
git clone https://github.com/t4skforce/docker-prune.git
cd docker-prune
Install dependencies using pipenv:
pip install pipenv
pipenv install --dev
Activate the virtual environment:
pipenv shell
Run the tool locally:
python -m docker_prune.cli --help
You can build and run the tool using Docker for testing in an isolated environment.
docker build -t docker-prune:latest -f docker/Dockerfile .
docker run -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-e TZ=Europe/Berlin \
-e DOCKER_PRUNE_SCHEDULE='*/10 * * * *' \
-e DOCKER_PRUNE_DEBUG=false \
docker-prune:latest
Contributions are welcome! Feel free to open issues or submit pull requests.
If you encounter any bugs or have feature requests, please open an issue on the GitHub repository.
This project is licensed under the MIT License. See the LICENSE file for details.
Content type
Image
Digest
sha256:032a1c056…
Size
26.2 MB
Last updated
6 days ago
docker pull t4skforce/docker-prune