Comment on page
Docker Commands Cheat Sheet
Docker Commands - A quick reference guide to Docker CLI commands used on a daily basis: usage, examples, snippets and links.
In this article I will highlight the 6 key docker commands I use on a daily basis while using Docker in the real world.
By no means is this an extensive list of commands, I kept it short on purpose so you could use it as a quick reference guide. I’ve also omitted the topic of building images and the commands that are associated with that.
At the bottom of the page, I’ll also put some good links to other Docker resources I like or frequently use.
Normally I will use this command just as often as I use
lscommand on a *NIX terminal. It’s especially useful when you first SSH to a machine to check what’s running. It’s also useful during the development and configuration process since you’ll likely have containers stopping/starting/crashing.
docker ps Example Output
This is probably my 2nd most popular command. Normally I am using this while trying to debug a container and need to shell into the container. Just note the
-iflag means interactive and
-tmeans TTY (aka a teletype terminal).
Also, you can use any command instead of
/bin/sh; I only put that here because I frequently am SSHing into an alpine image which doesn’t support bash.
docker exec -it Example Output
I debated putting this command in here, since I don’t use it all that often, but it’s a nice to have. Great example of when to use this - you change your prometheus configuration and need it to pick up the changes in your config file. You might also use this when resizing a volume.
Other commands you might use often, but I didn’t think were so worthy of their own section are
docker start(see docs) and
docker stop(see docs). You’ll use these commands normally when setting up or testing images and you’ll likely use a lot of flags. I didn’t think they were so applicable because you should honestly be using docker compose or some other orchestration system (like Amazon ECS or Kubernetes) to launch your containers.
I’m normally using this command when I am trying to figure out optimal soft/hard limits for containers. You might also use this if you are debugging which container is using most of your host’s resources.
docker stats Example Output
This one doesn’t come up to often, but it has, especially when you are building lots of images on a box or you are storing lots of data (like prometheus). If you are, you might consider setting up a cron job to prune your images and volumes on a recurring basis.
docker system df Example Output
docker system prune -af
- Description: Remove all unused images (dangling and unreferenced), containers, networks, and volumes.
You’ll probably only use this command on a Docker build machine or on your dev box, nevertheless take note, cause you are likely to use it.
docker system prune -af Example Output
crontab -l Example Output
- Docker Crash Course - If you’re new to docker this is a great crash course. Starts from installing docker all the way to docker compose. It can be a lot to take in so you might have to read it a couple times.
You can download this entire blog article with the "Export as PDF" link in the top right of this page (you might have to be on the desktop version. Additionally, below I've provided some PDFs from the web I have found useful.
Official Docker Cheat Sheet
Red Hat Developer Cheat Sheet
Docker Cheat Sheet V3 by @dockerlux