8  Cleaning Up

Now having gone through some activities in this course, you may find you’re acquiring quite a list of images and containers.

This is okay for a time, but note that these containers and images do take up space on your computer. If you have too many running and too many stored, you’ll run out of space for other stuff on your computer and it might start to get slow or otherwise unhappy with you.

8.1 Activity Instructions

8.2 Docker

To remove a container we can run:

docker rm <PUT_CONTAINER_ID_HERE>

This means you’ll need to grab the container ID, either from Docker desktop or by running docker ps.

Note! If you try to remove an image that is currently being used to run a container you won’t be allowed to! So stop and remove containers first, then you can remove the image.

Below are some kind of destructive actions, its going to delete potentially a lot of containers and images if you run these so just beware.

8.2.0.1 Remove non-running containers

docker rm $(docker ps -a -q)

8.2.0.2 Stop all containers

docker stop $(docker ps -a -q)

8.2.0.3 Remove all images

docker rmi -f $(docker images -q)

8.3 Podman

To remove a container we can run

docker rm <PUT_CONTAINER_ID_HERE>

This means you’ll need to grab the container ID by running podman ps.

To remove an image we can run

docker rmi <PUT_IMAGE_NAME_OR_ID_HERE>

This means you’ll need to grab the container ID, either from Docker desktop or by running docker image ls.

Note! If you try to remove an image that is currently being used to run a container you won’t be allowed to! So stop and remove containers first, then you can remove the image.

Below are some kind of destructive actions, its going to delete potentially a lot of containers and images if you run these so just beware.

8.3.0.1 Remove all non-running containers

podman rm $(podman ps -a -q)

8.3.0.2 Stop all containers

podman stop $(podman ps -a -q)

8.3.0.3 Remove all images

podman rmi -f $(podman images -q)