Docker commands

calendar_today timer Reading time ~1 minute

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

  1. Listing
  2. Removing
  3. Killing
  4. Some useful options to know

Listing

Images on your machine

Lists all the images on your machine, including the dangling ones

$ docker images -a

Running containers

$ docker ps

All containers

And their info

$ docker ps -a

Only the IDs of all containers

$ docker ps -qa

Removing

A container that was stopped

$ docker rm ID

All containers that were stopped

$ 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

$ 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.

$ 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.

$ docker system prune --all

removal result


Killing

One or more containers

Just pass a list of IDs to kill more than one container

$ 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.

animated jess' signature

Related Articles