Docker Container Cleanup – Short Cuts
Cleaning up your docker container can be useful. I need to cleanup my Docker container frequently as part of developing and testing the code that is running inside. I got tired of doing cut and paste of container and image ids. So I created a couple of shortcuts.
First I created bash aliases to save some typing.
alias dcrun="docker ps -a -q --filter="status=running"" alias dcall="docker ps -a -q"
dcrun will print out the running container ids in a single column list
dcall will print out all of the container ids in a single column list
I am a bit old-fashioned and hate typing dollar signs and parentheses so I use the xargs program instead.
xargs will work with any program. It basically takes all of the input that is being piped in and adds it as parameters to the end of the command that you are running.
To stop all running containers:
dcrun | xargs docker stop
To remove all containers:
dcall | xargs docker rm
The other way with dollar signs and parentheses:
docker rm -v $(docker ps -a -q -f status=exited)
Some tips on handling images from multiple repositories and nuances of the docker run command
- Domain Driven Design Catalog to Tame Microservice Sprawl
- Microservice Architecture and Your Logical Application
- Microservice Configuration Management
- Continuous Deployment and DevOps at Scale
- Register for DeployHub Team
- Reverse Proxy Setup for SaaS Deployments
- DeployHub Team User Guide
- The Hipster Store Tutorial
Ortelius Open Source Project
All Blogs on Kubernetes Microservices
- Microservice Configuration Management Blogs
- What is Configuration Management?
- How to Navigate the Deathstar
- Microservice Continuous Integration – Where’s the Build?
- Working with Helm for your Microservices Releases
- On Versioning your Container Content
- Versioning Lambda Functions
- How to Use a Domain Driven Design
- Versioning Applications
- Why we need Application Packages for CD
- Agentless Deployments with DeployHub’s Engine
- Version Jumps and Tracking
- How are Microservices and Applications Related?
- Migrate to Microservices with a Domain Driven Design
- Docker ‘Run’ May Not Work as You Expect