Featured
Docker: Mass Cleanup Command with Exceptions
Procedure and advanced console command to remove Docker images while preserving key components of critical services.
Technical difficulty:
0views
🚀 The Advanced Command
Sección titulada «🚀 El Comando Avanzado»When managing database servers or services integrated with Docker, local storage can quickly saturate with orphaned or obsolete images. To perform a mass cleanup while preserving images associated with a specific service (for example, Plane), we use the following Bash pipeline:
docker images | grep -v "plane" | grep -v "REPOSITORY" | awk '{print $3}' | xargs -r docker rmi⚠️ Important Warning regarding Dependencies
Sección titulada «⚠️ Advertencia Importante sobre Dependencias»Analyzing the structure of the Plane service suite, the following support base images are identified in the local engine: postgres, rabbitmq, minio, and valkey.
- Service Coupling: It is very likely that Plane requires and uses these images for its correct operational functioning (database storage, message queues, local S3, and caching).
- Docker Behavior: If you delete these base images, the next time you attempt to start Plane, Docker will be forced to download them from the public registry. Ensure you have a stable internet connection when you restart the containers.
- Active Security: If Plane containers are currently running on the server, the Docker daemon will block the deletion of associated images by default (preventing accidental service interruptions).
🛠️ Step-by-Step Pipeline Explanation
Sección titulada «🛠️ Explicación Paso a Paso del Pipeline»The command consists of 5 console tools optimally concatenated:
docker images: Lists all images installed locally on the host, showing columns such as repository, tag, and image ID.grep -v "plane": Filters and excludes (thanks to the-vparameter / invert match) any line containing the exclusion word, protecting the entire service stack.grep -v "REPOSITORY": Filters and discards the first line corresponding to the Docker output table headers.awk '{print $3}': Processes the remaining output and exclusively selects the third column, which contains the unique image identifier (IMAGE ID).xargs -r docker rmi: Receives the list of IDs from the previous step and executes the image removal command (docker rmi). The-rparameter (no-run-if-empty) prevents failures or broken syntax in the terminal if there are no images to delete.
📊 Docker Maintenance Checklist
Sección titulada «📊 Checklist de Mantenimiento Docker»- ✓ Preliminary Audit: Run
docker imagesmanually to map the current disk state. - ✓ Declarative Exclusion: Ensure that the exclusion terms in
grep -vcover all active production tags. - ✓ Execution Check: Prefer stopping the stack via Compose before performing aggressive engine cleanups.

