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

The 12 Days of Christmas - ITB 2022 Video Release— Day 2 - New Modules

The 12 Days of Christmas - ITB 2022 Video Release— Day 2 - New Modules

It's that time of year again. Trees are lit, presents are being wrapped, and relatives are coming to visit. That's right, it's time again for the 12 days of Christmas-- 2022 ITB Video Release Edition! 

Today, Day 2's Videos from Into the Box 2022 Conference, are all newly announced modules.

Gavin Pickin
Gavin Pickin
December 09, 2022
The 12 Days of Christmas - ITB 2022 Video Release— Day 1

The 12 Days of Christmas - ITB 2022 Video Release— Day 1

It's that time of year again.  Trees are lit, presents are being wrapped, and relatives are coming to visit.  That's right, it's time again for the 12 days of Christmas-- 2022 ITB Video Release Edition!

For the next 12 business days up until Christmas, we'll be releasing a series of related videos each day on the CFCasts site for our CFCasts Subscribers, and a announcement with titles, descriptions, and links to the videos, right here on the Ortus blog.  Consider it our early Christmas gift to you.

Gavin Pickin
Gavin Pickin
December 08, 2022
CommandBox Docker v3.6.3 Images Released

CommandBox Docker v3.6.3 Images Released

CommandBox 3.6.3 Docker images released



Today we are pleased to announce the release of version 3.6.3 of our CommandBox Docker images, which contains significant upgrades to the underlying CommandBox engine.

Most significantly, this release upgrades the CommandBox binary to 5.7.0. Read the Release Notes for this version here. This image version also adds new distro builds for the RHEL Universal Base Image. These images may be utilized by using the ubi9 in the image tag in the same way the alpine base images currently do.

Jon Clausen
Jon Clausen
December 08, 2022