Docker Cheatsheet

Most commonly used Docker commands. The Github repo could be found here.

Most Common Docker Commands

CommandExplanationShorthand
docker image lsLists all imagesdocker images
docker image rm <image>Removes an imagedocker rmi
docker image pull <image>Pulls image from a docker registrydocker pull
docker container lsLists running containersdocker ps
docker container ls -aLists all containersdocker ps -a
docker container run <image>Runs a container from an imagedocker run <image>
docker container rm <container>Removes a containerdocker rm <container>
docker container stop <container>Stops a containerdocker stop <container>
docker container exec <container>Executes a command inside the containerdocker exec <container>

Running and Stopping Containers

CommandExplanationExample
docker run <image>Running an imagedocker run ubuntu:20.04
docker run -t <image>Running tty without sending messagesdocker run -t ubuntu:20.04
docker run -it <image>Running tty and sending messagesdocker run -it ubuntu:20.04
docker run -d -it --name <container> <image> <command>Running tty and sending messages detached modedocker run -d -it --name loop ubuntu:20.04 sh -c "while true; do date; sleep 1; done"
docker logs -f <container>Outputs container’s logdocker logs -f loop
docker pause <container>Pauses containerdocker pause loop
docker unpause <container>Unpauses containerdocker unpause loop
  • -t creates tty
  • -i pass the STDIN to the container
  • --name <container> passes the container name

Sources