podman-rm(1)

πŸŽ€ podman-rm(1) πŸŽ€ β€” General Commands Manual

okay bestie, this is the podman-rm(1) page from the General Commands Manual, and it's all about yeeting containers. not images. containers. πŸ’…

πŸ’– NAME πŸ’–

podman-rm β€” Remove one or more containers

✨ SYNOPSIS ✨

podman rm [options] container

podman container rm [options] container

🌸 DESCRIPTION 🌸

Okay so podman rm removes one or more containers from the host. You can use the container name or ID. It does not remove images. And running or unusable containers are not removed without the -f option β€” no cap, they stay put. 🫢

πŸ”₯ OPTIONS πŸ”₯

🌈 --all, -a 🌈

Remove all containers. It can be used with -f too.

🧚 --cidfile=file 🧚

Read the container ID from the specified file and rm the container. Can be specified multiple times.

The command does not fail when the file is missing and you specified --ignore.

πŸ¦‹ --depend πŸ¦‹

Remove the selected container and recursively remove all containers that depend on it.

πŸ‘‘ --filter, -f=filter πŸ‘‘

Filter what containers rm acts on. Multiple filters can be given by using the --filter flag multiple times. Filters with the same key work inclusive, with the only exception being label, which is exclusive. Filters with different keys always work exclusive.

The valid filters are listed below:

  • id β€” [ID] Container's ID (CID prefix match by default; accepts regex)
  • name β€” [Name] Container's name (accepts regex)
  • annotation β€” [Key] or [Key=Value] Annotation assigned to a container
  • annotation! β€” [Key] or [Key=Value] Annotation NOT assigned to a container
  • label β€” [Key] or [Key=Value] Label assigned to a container
  • label! β€” [Key] or [Key=Value] Label NOT assigned to a container
  • exited β€” [Int] Container's exit code
  • status β€” [Status] Container's status: 'created', 'initialized', 'running', 'stopped', 'paused', 'exited', 'removing', 'stopping', 'unknown'
  • ancestor β€” [ImageName] Image or descendant used to create container (accepts regex)
  • before β€” [ID] or [Name] Containers created before this container
  • since β€” [ID] or [Name] Containers created since this container
  • volume β€” [VolumeName] or [MountpointDestination] Volume mounted in container
  • health β€” [Status] healthy or unhealthy
  • pod β€” [Pod] name or full or partial ID of pod
  • network β€” [Network] name or full ID of network
  • restart-policy β€” [Policy] Container's restart policy (e.g., 'no', 'on-failure', 'always', 'unless-stopped')
  • until β€” [DateTime] Containers created before the given duration or time.
  • command β€” [Command] the command the container is executing, only argv[0] is taken
  • should-start-on-boot β€” [Bool] Containers that need to be restarted after system reboot. True for containers with restart policy 'always', or 'unless-stopped' that were not explicitly stopped by the user

πŸ’€ --force, -f πŸ’€

Force the removal of running and paused containers. Forcing a container removal also removes containers from container storage even if the container is not known to Podman. For example, containers that are created by different container engines like Buildah. In addition, forcing can be used to remove unusable containers, e.g. containers whose OCI runtime has become unavailable.

πŸ“ --ignore, -i πŸ“

Ignore errors when specified containers are not in the container store. A user might have decided to manually remove a container which leads to a failure during the ExecStop directive of a systemd service referencing that container.

Further ignore when the specified --cidfile does not exist as it may have already been removed along with the container.

πŸ§ƒ --latest, -l πŸ§ƒ

Instead of providing the container name or ID, use the last created container. Note: the last started container can be from other users of Podman on the host machine. (This option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines)

⏳ --time, -t=seconds ⏳

Seconds to wait before forcibly stopping the container. Use -1 for infinite wait.

⚠️ The --force option must be specified to use the --time option.

🫧 --volumes, -v 🫧

Remove anonymous volumes associated with the container. This does not include named volumes created with podman volume create, or the --volume option of podman run and podman create.

✨ EXAMPLES ✨

okay bestie, this is the part where it all clicks πŸ’– every one of these is copy-pasteable, no cap.

  • remove a container by name β€” literally just hand it the name:
$ podman rm mywebserver
  • remove a container and everything depending on it β€” --depend said "you're coming with me" πŸ’…:
$ podman rm --depend mywebserver
  • remove a bunch of containers at once β€” names or IDs, mix and match, she doesn't care:
$ podman rm mywebserver myflaskserver 860a4b23
  • remove containers whose IDs you read from files β€” one --cidfile per container, stack 'em up πŸŽ€:
$ podman rm --cidfile ./cidfile-1 --cidfile /home/user/cidfile-2
  • forcibly nuke a container by ID β€” -f is the main character here:
$ podman rm -f 860a4b23
  • force remove, but give it a grace period β€” --time 2 means wait 2 seconds before sending SIGKILL, so it's got a lil moment to go quietly 😌:
$ podman rm --time 2 --force 860a4b23
  • force remove with zero patience β€” --time 0 equals no waiting at all, instant, gone, bye πŸ‘‹:
$ podman rm --time 0 --force 860a4b23
  • remove literally everything, running or not β€” -f -a, the scorched-earth combo πŸ”₯:
$ podman rm -f -a
  • forcibly remove the last created container β€” okay important caveat bestie: this option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines 🫢:
$ podman rm -f --latest
  • remove by name β€” using --filter name=test-alpine, and look, it even shows you the ID it ate:
$ podman rm --filter name=test-alpine
34f997d354017a0076402c3a79245a5b8bd11b597c84385bec25ae8941fd5238
  • remove by label β€” --filter label=app=frontend, chef's kiss for cleaning up a whole app tier πŸ“:
$ podman rm --filter label=app=frontend
5a3694a13436168ea99490e74b489566c646d6a0db29868f57113298110d1b1c
  • remove by status β€” --filter status=exited sweeps up all the ones that already clocked out πŸ’€:
$ podman rm --filter status=exited
4a3332649ed8bec1e0d82e113074b9a13d45582007aeac969c005992cc480a73
f8e85f84a749b205fb602895afa6ec8a866045ff27b82f843033712c8b93a2c9
7d17e850c9b172f11a3e20bab81da6fc694c35c2dc38d84083eb57869dcaca63
47972eb04aa7c77705b597a929957d1e8a392e00b44c0a2a7f88a01f9f860d11
  • remove by ancestor β€” --filter ancestor=nginx finds every container spawned from that image πŸ¦‹:
$ podman rm --filter ancestor=nginx
8a7668cdec27664559a7da55ed5cda101f904441f7245e248218580656b2bae3
0d297b336bf31d141c7720a791c45dafdb8b5033deaab12f29b88e5bff6b122d
134475ac5140687d1eefff19f937dc24755f6c18e37e11d61b1084b59f1bdbe2
  • remove by volume β€” --filter volume=web-vol, for the containers still holding onto that volume:
$ podman rm --filter volume=web-vol
b3f4d4c6a67e2ef1e089efdc8ff3a47dba008eb0ff1e53ae60f59279cb43f9ba
  • remove by network β€” --filter network=web-net, same energy, network edition 🌈:
$ podman rm --filter network=web-net
1c057cac90c0512df86197599eef5a9485afc900b1ade03c9739fa24c360bbda
  • remove containers but ignore the ones that don't exist β€” --ignore is that friend who does NOT do drama 😭 notice how nonexistent-container just gets skipped and the existing ones go through:
$ podman rm --ignore mycontainer1 mycontainer2 nonexistent-container
mycontainer1
mycontainer2

πŸ’… Exit Status

fr fr, this is how you know what actually happened:

  • 0 β€” all specified containers removed πŸ‘‘ slay
  • 1 β€” one of the specified containers did not exist, and no other failures
  • 2 β€” one of the specified containers is paused or running
  • 125 β€” the command fails for any other reason πŸ’€

πŸ‘€ SEE ALSO


πŸŽ€ HISTORY

August 2017, Originally compiled by Ryan Cole rycole@redhat.com ⟨mailto:rycole@redhat.com⟩ β€” shoutout to the original author, we love an icon 🫢


and that's the whole page bestie, you made it πŸ’– this one's officially from the podman-rm(1) manual, dated August 2017 β€” go forth and delete responsibly (or with -f, we don't judge) ✨🌸

πŸ“¦ where this page comes from