Skip to content

Instantly share code, notes, and snippets.

@mze3e
Last active April 2, 2021 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mze3e/80923d8f22dd751b03c92ec02aea6531 to your computer and use it in GitHub Desktop.
Save mze3e/80923d8f22dd751b03c92ec02aea6531 to your computer and use it in GitHub Desktop.
Docker CheatSheet
#Docker Cheatsheet
##Build
Build an image from the Dockerfile in the current directory and tag the image
docker build -t <IMAGE_NAME>:1.0 .
List all images that are locally stored with the Docker Engine
docker image ls
Delete an image from the local image store
docker image rm alpine:3.4
##Share
Pull an image from a registry
docker pull myimage:1.0
Retag a local image with a new image name and tag
docker tag myimage:1.0 myrepo/myimage:2.0
Push an image to a registry
docker push myrepo/myimage:2.0
##Run
Run a container from the Alpine version 3.9 image, name the running container “web” and expose port 5000 externally, mapped to port 80 inside the container.
docker container run --name <CONTAINER_NAME> -p 5000:80 alpine:3.9
Stop a running container through SIGTERM
docker container stop <CONTAINER_NAME>
Stop a running container through SIGKILL
docker container kill <CONTAINER_NAME>
List the networks
docker network ls
List the running containers (add --all to include stopped containers)
docker container ls
Delete all running and stopped containers
docker container rm -f $(docker ps -aq)
Print the last 100 lines of a container’s logs
docker container logs --tail 100 <CONTAINER_NAME>
##Cleanup
List all exited containers
docker ps -a -f status=exited
Purging All Dangling Images, Containers, Volumes, and Networks
docker system prune
Purging All Unused and Dangling Images, Containers, Volumes, and Networks
docker system prune -a
List containers using more than one filter
docker ps -a -f status=exited -f status=created
Remove containers using more than one filter
docker rm $(docker ps -a -f status=exited -f status=created -q)
List one or more specific volumes - Docker 1.9 and later
docker volume ls
Remove one or more specific volumes - Docker 1.9 and later
docker volume rm volume_name volume_name
List dangling volumes - Docker 1.9 and later
docker volume ls -f dangling=true
Remove dangling volumes - Docker 1.9 and later
docker volume prune
Remove a container and it's volume
docker rm -v <CONTAINER_NAME>
##Docker Compose
Start Docker Container
docker-compose up -d
Stop Docker Container
docker-compose down
##Docker Logon To Terminal
Login as default user
docker exec -it <CONTAINER_NAME> /bin/bash
Login as root user
docker exec -u 0 -it <CONTAINER_NAME> bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment