Docker cheatsheet

This cheat sheet features the most important and commonly used docker commands for easy reference. Docker Tips and Tricks (A collection of useful tips and tricks for Docker)

Table of contents

  1. Docker Commands
  2. The Ultimate Docker Cheat Sheet
  3. Stop all containers
  4. Remove all containers
  5. Stop and remove all images and containers
  6. Remove all images
  7. Remove all untagged containers
  8. Connect to a docker container
  9. See all space Docker take up
  10. Get IP address of running container
  11. Kill all running containers
  12. Removing All Unused Objects

Docker Commands

The Ultimate Docker Cheat Sheet

Stop all containers

NOTE: This will stop ALL your containers.

docker stop $(docker ps -aq)

Remove all containers

NOTE: This will remove ALL your containers.

docker rm $(docker ps -a -q)

Stop and remove all images and containers

NOTE: This will remove ALL your images/containers.

docker stop $(docker ps -aq) && docker rm $(docker ps -aq) && docker rmi $(docker images -q)

Remove all images

NOTE: This will remove ALL your images.

docker rmi $(docker images -q)

Remove all untagged containers

docker rmi $(docker images | grep '^<none>' | awk '{print $3}')

Connect to a docker container

sudo docker exec -i -t [CONTAINER ID] /bin/bash

See all space Docker take up

docker system df

Get IP address of running container

docker inspect [CONTAINER ID] | grep -wm1 IPAddress | cut -d '"' -f 4

Kill all running containers

docker kill $(docker ps -q)

Removing All Unused Objects

$ docker system prune
$ docker system prune --volumes
$ docker network prune #Remove all unused networks