Skip to content

Instantly share code, notes, and snippets.

@chris-burkhardt
Last active May 3, 2020 23:25
Show Gist options
  • Save chris-burkhardt/0fbae78c69767f540bbe9acade8d4d33 to your computer and use it in GitHub Desktop.
Save chris-burkhardt/0fbae78c69767f540bbe9acade8d4d33 to your computer and use it in GitHub Desktop.
Docker Command Cheat Sheet
Most frequently used Docker commands:
-----------------------------------------------------------------
ALL CONTAINERS - delete
-----------------------------------------------------------------
## Main ways to remove all images/containers
docker rm $(docker ps -a -q)
docker rmi -f $(docker images -q)
## Delete all running and stopped containers
docker container rm -f $(docker ps -aq)
-----------------------------------------------------------------
KILL CONTAINERS
-----------------------------------------------------------------
## Kill a container by sending a SIGKILL to a running container:
docker kill [CONTAINER]
## Killing single or multiple containers (just use the first 2 digits of container id)
docker kill a8 c4
## Kill all containers
docker kill $(docker ps -q)
-----------------------------------------------------------------
# REMOVING containers/images
-----------------------------------------------------------------
## Remove killed containers in Exited status
docker rm $(docker ps -q -f status=exited)
## Removes a container after it stops
docker run --rm [IMAGE]
## Removes specific image
docker rmi [IMAGE]
-----------------------------------------------------------------
# DELETING images and containers
-----------------------------------------------------------------
## Delete an image from the local image store
docker image rm alpine:3.4
## Delete a container if its not running
docker rm [CONTAINER]
-----------------------------------------------------------------
# Listing containers and images
-----------------------------------------------------------------
## List the running containers (add --all to include stopped containers)
docker container ls
## List all images that are locally stored with the Docker Engine
docker images ls
## Lists both running containers and ones that have stopped
docker ps -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment