Blog

CONTAINERS2017 - Removing Containers

Luis Majano September 14, 2017

Spread the word

Luis Majano

September 14, 2017

Spread the word


Share your thoughts

The Docker CLI has an extensive suite of commands built-in and it can be painful to remember all of them. So as part of our containers roadshow, we will be blogging about useful tips and tricks for working with containers. We all make mistakes and we all need to be able remove containers from time to time. So let's go ahead and start!

Remove one or more specific containers

Use the docker ps command with the -a flag to locate the name/ID of the containers you want to remove:

# list
docker ps -a

# remove
docker rm ID/nameID/name

Remove Container Upon Exit

If you want to cleanup after yourself, then you can automatically delete a container once it exists from runnable operation using the docker run --rm command.

docker run --rm image_name

Remove All Exited Containers

You can locate containers using docker ps -a and filter them by their status: created, restarting, running, paused, or exited. To review the list of exited containers, use the -f flag to filter based on status. When you've verified you want to remove those containers, using -q to pass the IDs to the docker rm command.

docker ps -a -f status=exited
docker rm $(docker ps -a -f status=exited -q)

Remove Containers Using More Than 1 Filter

Docker filters can be combined by repeating the filter flag with an additional value.

docker ps -a -f status=exited -f status=created
docker rm $(docker ps -a -f status=exited -f status=created -q)

Remove Containers According to Patterns

You can find all the containers that match a pattern using a combination of docker ps and grep. When you're satisfied that you have the list you want to delete, you can use awk and xargs to supply the ID to docker rmi. Please note this will only work on unix based systems.

docker ps -a |  grep "pattern”
docker ps -a | grep "pattern" | awk '{print $3}' | xargs docker rmi

Stop and remove all containers

You can review the containers on your system with docker ps. Adding the -a flag will show all containers. Then you can get funky and pass them to the stop or rm commands.

docker ps -a
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

Add Your Comment

Recent Entries

BoxLang 1.0.0 Beta 7 Launched

BoxLang 1.0.0 Beta 7 Launched

We are pleased to announce the release of BoxLang 1.0.0-Beta 7! This latest beta version includes improvements and essential bug fixes, but more importantly it certifies the execution of ColdBox HMVC and TestBox.

What is BoxLang?

BoxLang is a modern dynamic JVM language that can be deployed on multiple runtimes: operating system (Windows/Mac/*nix/Embedded), web server, lambda, iOS, android, web assembly, and more. BoxLang combines many features from different progr

Luis Majano
Luis Majano
July 26, 2024
New BoxLang Feature: Java Method References and Higher-Order Functions

New BoxLang Feature: Java Method References and Higher-Order Functions

We’ve added more goodies to our BoxLang Java interop: method references and higher-order functions. CFML has never let you do these things, making Java Interop feel like a second-class citizen. But with BoxLang, we’re elevating Java integration to a new level.

Maria Jose Herrera
Maria Jose Herrera
July 26, 2024
Level Up Your ColdFusion Skills with our Virtual Live Training: ColdBox from Zero to Hero

Level Up Your ColdFusion Skills with our Virtual Live Training: ColdBox from Zero to Hero

Level Up Your ColdFusion Skills with our Virtual Live Training: ColdBox from Zero to Hero

Are you a CFML developer looking to take your skills to the next level? Look no further than the ColdBox from Zero to Hero Virtual Live Training! This intensive two-day course will equip you with the knowledge and expertise to build robust and scalable applications using ColdBox 7, the latest version of the most popular CFML MVC framework.

What You'll Learn:

  • Master the Fun...

Cristobal Escobar
Cristobal Escobar
July 24, 2024