Docker CLI Cheat Sheet

Command

Description

Example

Image Management

1

docker build

Builds an image from a Dockerfile

docker build -t my_image_name .

2

docker pull

Downloads an image from a registry

docker pull ubuntu:latest

3

docker push

Pushes an image to a registry

docker push my_image_name

4

docker images

Lists all images

docker images

5

docker rmi

Removes an image

docker rmi ubuntu:latest

6

docker image prune

Removes all unused images

docker image prune

Container Management

7

docker run

Runs a container from an image

docker run -it ubuntu bash

8

docker ps

Lists all running containers

docker ps

9

docker stop

Stops a running container

docker stop my_container

10

docker start

Starts a stopped container

docker start my_container

11

docker rm

Removes a stopped container

docker rm my_container

12

docker container prune

Removes all unused containers

docker container prune

Interacting with Containers

13

docker exec

Executes a command in a running container

docker exec my_container ls -l

14

docker logs

Shows the logs of a container

docker logs my_container

15

docker attach

Attaches your terminal to a running container

docker attach my_container

16

docker cp

Copies files between your host and a container

docker cp my_file my_container:/destination

Network Management

17

docker network create

Creates a new network

docker network create my_network

18

docker network connect

Connects a container to a network

docker network connect my_network my_container

19

docker network list

Lists all networks

docker network list

Volume Management

20

docker volume create

Creates a new volume

docker volume create my_volume

21

docker volume inspect

Shows information about a volume

docker volume inspect my_volume

22

docker volume rm

Removes a volume

docker volume rm my_volume

General Commands

23

docker version

Shows the Docker version

docker version

24

docker info

Shows information about the Docker daemon

docker info

25

docker help

Shows help for a specific command

docker help build

26

docker run -d

Runs a container in the background

docker run -d ubuntu