Docker
containers.docker
Protects against destructive Docker operations like system prune, volume prune, and force removal
- 9blocking rules
- 10safe patterns
- 7High
- 2Medium
[packs]
enabled = ["containers.docker"]Evaluated when a command contains docker, prune, rmi, volume.
Recorded verdicts
docker system prune -af --volumesBlockedcontainers.docker:system-prunedocker ps -aAllowed
Blocking rules
Each rule ID is containers.docker:<name>. Use it in allowlists and [policy.rules].
Highnetwork-prunedocker network prune removes ALL unused networks.
Explanation
docker network prune removes all user-defined networks not used by any container. While less destructive than volume prune, it can still cause issues: - Custom network configurations are lost - Containers may fail to communicate after restart - Service discovery between containers breaks Preview unused networks: docker network ls docker network ls -f dangling=true Safer alternative: docker network rm <specific-network>
Highrm-forcedocker rm -f forcibly removes containers, potentially losing data.
Explanation
docker rm -f forcibly stops and removes containers. This is dangerous because: - Running processes are killed immediately (SIGKILL) - No graceful shutdown - data may be corrupted - In-flight requests are dropped - Uncommitted data in the container is lost Safer approach: docker stop <container> # Graceful shutdown (SIGTERM) docker rm <container> # Then remove Check container status first: docker ps -a | grep <container>
Highrmi-forcedocker rmi -f forcibly removes images even if in use.
Explanation
docker rmi -f forcibly removes images, even if containers are using them. This can cause: - Running containers to fail on restart - Broken references to deleted layers - Loss of build cache Check what's using the image: docker ps -a --filter ancestor=<image> Safer approach: docker rmi <image> # Fails safely if in use
Highstop-allStopping/killing all containers can disrupt services. Be specific about which containers.
Explanation
This pattern stops or kills ALL running containers on the system. This is dangerous in shared environments: - Production services go down - Database connections are severed - In-flight requests fail - Other users' containers are affected Be specific instead: docker stop <container-name> # Stop by name docker stop $(docker ps -q -f name=myapp) # Filter by name (dcg gates any stop over a $(docker ps ...) expansion, so this form still needs approval) Preview what would be stopped: docker ps --format '{{.Names}}: {{.Status}}'
Highsystem-prunedocker system prune removes ALL unused containers, networks, images. Use 'docker system df' to preview.
Explanation
docker system prune is Docker's most aggressive cleanup command. It removes: - All stopped containers - All networks not used by at least one container - All dangling images (untagged) - All dangling build cache With -a flag, it also removes all unused images, not just dangling ones. With --volumes flag, it removes all unused volumes (data loss!). Preview what would be removed: docker system df # Show disk usage docker system df -v # Verbose with details Safer alternative: docker container prune # Only stopped containers docker image prune # Only dangling images
Highvolume-prunedocker volume prune removes ALL unused volumes and their data permanently.
Explanation
docker volume prune permanently deletes ALL volumes not currently attached to a running container. This is extremely dangerous because: - Database data stored in volumes is lost forever - Application state and uploads are destroyed - There is NO recovery mechanism Even stopped containers' volumes are considered 'unused' and will be deleted. Preview before pruning: docker volume ls # List all volumes docker volume ls -f dangling=true # Show only unused Safer approach: docker volume rm <specific-volume> # Remove by name
Highvolume-rmdocker volume rm permanently deletes volumes and their data.
Explanation
docker volume rm permanently deletes named volumes and all data stored in them. This is irreversible: - Database files are gone - User uploads are lost - Configuration data is destroyed - No trash or undo mechanism exists Check volume contents first: docker run --rm -v <volume>:/data alpine ls -la /data Consider backing up: docker run --rm -v <volume>:/data -v $(pwd):/backup alpine \ tar czf /backup/volume-backup.tar.gz /data
Mediumcontainer-prunedocker container prune removes ALL stopped containers.
Explanation
docker container prune removes all stopped containers. This is relatively safe but can cause issues: - Container logs are lost - Container filesystem layers are deleted - Cannot restart or inspect removed containers Preview stopped containers: docker ps -a -f status=exited docker ps -a -f status=created Consider keeping recent containers for debugging.
Mediumimage-prunedocker image prune removes unused images. Use 'docker images' to review first.
Explanation
docker image prune removes 'dangling' images (untagged layers). With -a flag, it removes ALL images not used by existing containers. Consequences: - Build cache layers are deleted (slower rebuilds) - With -a: base images must be re-pulled Preview what would be removed: docker images -f dangling=true docker images # With -a flag Usually safe, but may slow down builds.
Safe patterns
Checked first. A command that matches one is never blocked by this pack.
docker-psdocker-imagesdocker-logsdocker-inspectdocker-builddocker-pulldocker-rundocker-execdocker-statsdocker-dry-run