Show Menu

Docker basics Cheat Sheet by

Basic docker commands, for beginners. by TheFax



build is the process of building Docker images using a Docker­file.
a container is a runtime instance of a Docker image.
a Dockerfile is a text document that contains all the commands you would normally execute manually in order to build a Docker image. Docker can build images automa­tically by reading the instru­ctions from a Docker­file.
Docker Daemon
the background service running on the host that manages building, running and distri­buting Docker contai­ners. The daemon is the process that runs in the operating system which clients talk to.
a Docker image is a read-only template that contains a set of instru­ctions for creating a container.
a group of containers that runs together in order to create a service. Example: [wordp­ress] + [mySql]
Docker volumes are file systems mounted into a Docker containers to preserve data generated by the running container.
Author this cheat sheet has been created by TheFax

Run containers

docker run
Run in background / detached mode
Intera­ctive, tty
Remove container after it stops.
-p 83:80
Port mapping host:c­ont­ainer
-v /dirHost:/dir
Mount file or direct­ories /host/­dir­:/c­ont­ain­er/dir
--name pluto
Set container name
--restart no
Restart policy:
no: stops the container when it exit.
on-failure[:max-­ret­ries]: Restart only if the container exits with a non-zero exit status. Option­ally, limit the number of restart retries.
always: restart the container regardless of the exit status. The container will also always start on daemon startup.
unless­-st­opped: Always restart the container regardless of the exit status, except if the container was put into a stopped state.
Image name is the LAST parameter.

Manage containers

docker start/stop CONTAINER
Start or stop a container
docker pause/­unpause CONTAINER
Pause or unpause a container
docker restart CONTAINER
Stop and restart a container
docker attach CONTAINER
Connect terminal to a running container
docker rename OLD_NAME NEW_NAME
Rename a container
docker container rm CONTAINER
docker rm CONTAINER
Remove the specified container
docker container rm -f CONTAINER
docker rm -f CONTAINER
Force the removing of specified container.
docker container prune
Delete all stopped containers

Manage images

docker rmi IMAGE, or docker image rm IMAGE
Remove image
docker build URL
Create an image from a dockerfile
Create an image from a container
docker search TERM
Search the Docker Hub for images


docker stats
Live data about running containers
docker ps
List running containers
docker ps -a
List ALL contai­ners, also stopped ones
docker port CONTAINER
List port mapping of specified container
docker image ls, or docker images
List all locally stored images
docker container ls
List running containers
docker container ls -a
List all containers
docker volume ls
List volumes

Tips :-)

Where are docker images and files?
How can I refer to a container?
Via its name (set by --name Pluto) or...
Via its ID (example: 4a7f7e­eba­e0f­631­78a­ff7­eb0­aa3­9f0­627­a20­3ab­2df­258­c1a­00b­456­cf2­0063) or...
Via the first letters of its ID (example: 4a7f)
How can I test my docker?
Try one of these commands:
docker run hello-­world
docker run -it --rm -d --name test -p 83:80 nginx


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Docker & Swarm 2022 Cheat Sheet
          Master Measures & Weights with this Cheat Sheet Cheat Sheet

          More Cheat Sheets by foobar

          COSC-3353-Ch3at Sheet Cheat Sheet