Docker CLI cheat sheet

Basic Docker Commands

docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Downloads image

-q less verbose

$ docker pull jenkins/jenkins:lts-jdk11


Creates a new container

-d run a container in background and print container id
–name assign a name to the container
-p <local port>:<container port> publish container’s port to the host
-v <local file system>:<container file system> mount a volume

$ docker run -d –name jenkins -p 8085:8080 -v “/docker_volume/jenkins”:/var/jenkins_home jenkins/jenkins:lts-jdk11

docker images [OPTIONS] [REPOSITORY[:TAG]]

Lists all images, repositories, tags and their size

-a show all images (default hides intermediate images)

docker build [OPTIONS] PATH | URL | -

Build an image from the docker file, by default it looks for ‘Dockerfile’

$ docker build .


Execute a command in a running container

-i interactive mode, keeps STDIN open
-t Allocate a pseudo-TTY

$ docker container exec -it mariadb /bin/bash


docker rmi [OPTIONS] IMAGE [IMAGE…]

Remove one or more images

-f force remove image

$ docker rmi -f 8b7c2b10838b 1a7a055a6252


Remove one or more containers

-f force remove running container


docker container start [OPTIONS] CONTAINER [CONTAINER…]

Start one or more containers

-i interactive mode; attach container’s STDIN

$ docker container start jenkins

docker container stop [OPTIONS] CONTAINER [CONTAINER…]

Stop one or more containers

$ docker container stop jenkins

docker container ls [OPTIONS]

List containers

-a show all containers (default shows just running)
-q only display container id’s
-s display total file size

$ docker container ls

docker container logs [OPTIONS] CONTAINER

Display logs of the container

-f follow log output
–tail <number> number of lines to show from the end of the log

$ docker container logs –tail 5 jenkins

docker container exec [OPTIONS] CONTAINER COMMAND [ARG…]

Run a command in a running container

-d run command in the background
-i interactive mode, keep STDIN open
-t allocate a pseudo-TTY

$ docker container exec -it jenkins /bin/bash

docker container diff CONTAINER

List changed files and directories on the container

$ docker container diff jenkins

docker container stats [OPTIONS] [CONTAINER…]

Display live stream on container resource usage statistics

$ docker container stats jenkins

docker container inspect [OPTIONS] CONTAINER [CONTAINER…]

Display detailed information on one or more container’s

$ docker container inspect jenkins

docker container kill [OPTIONS] CONTAINER [CONTAINER…]

Kill one or more running container’s

$ docker container kill jenkins