If you deal with Docker on a daily basis, you need to know a few commands. If you’re like me and forget these things, here’s a cheat sheet to help ;)
Summary
Listing
Images on your machine
Lists all the images on your machine, including the dangling ones
1
$ docker images -a
Running containers
class="highlight">1
$ docker ps
All containers
And their info
class="highlight">1
$ docker ps -a
Only the IDs of all containers
class="highlight">1
$ docker ps -qa
Removing
A container that was stopped
class="highlight">1
$ docker rm ID
All containers that were stopped
class="highlight">1
$ docker rm $(docker ps -qa)
An image from the system
If the image isn’t in use, you can remove it using the command below along with the image ID
class="highlight">1
$ docker rmi ID
All images from the system
Removes ALL Docker images that aren’t in use from your machine. Use with care!
It’ll show an error if any image is in use.
class="highlight">1
$ docker rmi $(docker images -qa)
All images from the system
Removes ALL Docker images that aren’t in use from your machine. Use with care!
It’ll ignore images in use.
class="highlight">1
$ docker system prune --all

Killing
One or more containers
Just pass a list of IDs to kill more than one container
class="highlight">1
$ docker kill ID
Some useful options to know
-a
Most, if not all, Docker commands and subcommands have an -a option which comes from all.
–rm
Same thing happens with the --rm option. When used, it indicates that the container should be removed after its execution.
-q
Most, if not all, Docker commands and subcommands have a -q option that lists only the IDs.
Related Articles
english Playing with Docker’s container listing
Learn to list and filter containers from the list
english Python and its versions: pyenv part 2
How pip packages work across Python versions installed with pyenv
english Python virtual environments: venv
Learn how to create virtual environments using Python's module venv