Docker Cheat Sheet

Problem Statement:

Way too many commands to remember for Docker command line

Solution:

This cheat sheet.  😆 

All commands below are called as options to the base docker command. Run docker --help for more information on a particular command.

app*Docker Application
assemble*Framework-aware builds (Docker Enterprise)
builderManage builds
clusterManage Docker clusters (Docker Enterprise)
configManage Docker configs
contextManage contexts
engineManage the docker Engine
imageManage images
networkManage networks
nodeManage Swarm nodes
pluginManage plugins
registry*Manage Docker registries
secretManage Docker secrets
serviceManage services
stackManage Docker stacks
swarmManage swarm
systemManage Docker
template*Quickly scaffold services (Docker Enterprise)
trustManage trust on Docker images
volumeManage volumes

Build

Build an image from the Dockerfile in the
current directory and tag the image:

docker build -t myimage: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 web -p 5000:80 alpine:3.9

Stop a running container through SIGTERM
docker container stop web

Stop a running container through SIGKILL
docker container kill web

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 web

Conclusion:

This is the way to do it.

Reference:

https://www.docker.com/sites/default/files/d8/2019-09/docker-cheat-sheet.pdf
https://technumero.com/display-code-snippets-in-wordpress/
https://dockerlabs.collabnix.com/docker/cheatsheet/

Tag Cloud