Docker Cheat Sheet (PDF)

Docker is fantastic tool for building out your infrastructure, however it does have a fairly steep learning curve. That’s why I created this Docker Cheat Sheet. I was constantly looking up what docker commands I needed to run to build an image from a dockerfile, run a container, mount a volume, etc.

Starting out I didn’t know you could map a local volume to your Docker container or that you had to prune your images quite regularly if you didn’t want to fill up your disk. Just glancing over this cheat sheet should help you map your server or VM knowledge over to Docker.

Docker Cheat Sheet PDF Download

Docker Process Management

# Show all running docker containers
docker ps

# Show all docker containers
docker ps -a

# Run a container
docker run <image>:<tag>

# Run a container and connect to it
docker run -it <image>:<tag>

# Run a container in the background
docker run -d <image>:<tag>

# Stop a container
docker stop <container>

# Kill a container
docker kill <container>

Docker Images and Repositories

# List available local images
docker images

# Search for docker images
docker search <image>

# Pull a docker image
docker pull <image>

# Build an image with a dockerfile
docker build -t <image>:<tag> <run_directory> -f <dockerfile>

# Login to a remote repository
docker login <repository>

# Push an image to your remotee repository
docker push <image>:<tag>

# Remove a local docker image
docker rmi <image>:<tag>

# Show metadata for an image
docker inspect <image>

# Remove all unused docker images
docker image prune

Docker Volumes and Ports

# List volumes
docker volume ls

# Create a volume
docker volume create <volume>

# Delete a volume
docker volume rm <volume>

# Show volume metadata
docker volume inspect <volume>

# Delete all volumes not attached to a container
docker volume prune

# Mount a local directory to your container
docker run -v <local_dir>:<container_dir> <image>

# Copy file or folder from a docker container to host machine
docker cp <container>:<container_dir> <local_dir>

# Copy file or folder from local machine onto a container
docker cp <local_dir> <container>:<container_dir>

# Map a local port to a docker instance
docker run -d -p 127.0.0.1:<local_port>:<docker_port> <image>

# List the ports a docker container is running on
docker port <container>

Docker Troubleshooting

# Show the logs of a container
docker logs <container>

# Follow/tail the logs of a container
docker logs -f <container>

# Show timestamps on docker logs
docker logs -t <container>

# Show details/metadata of a container
docker inspect <container>

# Show a 'top' view of processes running on a container
docker top <container>

# Show a 'top' view of all docker containers
docker stats

# Show any files that have changed since startup
docker diff <container>

# Connect to an already running container
docker attach <container>

# Execute a command on a container
docker exec -it <container_id> /bin/bash

# Show docker system wide information
docker system info

# Show docker disk space used
docker system df

Docker Compose

# Start your docker-compose defined resources in detached mode
docker-compose up -d -f <docker_compose_yaml>

# Stop all docker-compose resources
docker-compose stop

# Destroy all docker-compose resources
docker-compose down

# Show docker-compose processes
docker-compose ps

# Show docker-compose logs
docker-compose logs

# Show docker-compose resource consumption
docker-compose top

Wrap up

If you enjoyed this Docker Cheat Sheet, then be sure to check out our Kubernetes (kubectl) Cheat Sheet, Helm Cheat sheet, and Terraform Commands Cheat Sheet.

You may also like...

7 Responses

  1. November 22, 2020

    […] should be up and running on your Ubuntu system. To help you get started I also created a Docker CLI Cheat Sheet. The Cheat Sheet is a PDF that lets you copy, paste, and search with […]

  2. December 21, 2020

    […] a better Docker Cheat Sheet, Kubernetes Cheat Sheet and Helm Cheat Sheet at […]

  3. December 27, 2020

    […] If you like this cheat sheet be sure to check out the Docker CLI Cheat Sheet! […]

  4. January 1, 2021

    […] Docker CLI Cheat Sheet […]

  5. January 2, 2021

    […] Thanks for following through this article on Docker Compose environment variables. If this guide was useful for you be sure to bookmark it or add it to your team’s documentation. And if you’re a consistent user of Docker be sure to check out our Docker CLI Cheat Sheet. […]

  6. January 3, 2021

    […] first argument you pass when you run the container. For example if I wanted to curl the URL ‘https://swissarmydevops.com/containers/docker/docker-cli-cheat-sheet&#8216; it would look like […]

  7. January 4, 2021

    […] Thanks reading! Hopefully this helped clarify the Docker Image vs Container differences for you. If you liked this hands on tutorial be sure to check out our article on building your first Dockerfile as well as our Docker Cheat Sheet. […]

Leave a Reply

Your email address will not be published. Required fields are marked *