home
docker cheat sheet
Software container platform
print

docker version: 20.10+ - Date: June 2022

Installation

Documentation
https://docs.docker.com/engine/install/

Show the Docker version / information
docker version / info

Create a container

Run a container
docker run [options] IMAGE [COMMAND]

Run a httpd container in background
docker run -d httpd

Manage containers

List running containers
docker ps

List all containers
docker ps -a

Stop a running container
docker stop CONTAINER

Start a stopped container
docker start [options] CONTAINER

Remove a container
docker rm [-f] CONTAINER

Remove all containers
docker rm $(docker ps -a -q)

Manage images

Build an image from a Dockerfile
docker build -t IMAGE[:TAG] .

Search an image on Dockerhub
docker search IMAGE

Pull an image from Dockerhub
docker pull IMAGE[:TAG]

List all local images
docker image ls

Remove a local image
docker image rm IMAGE[:TAG]

Login to a registry
docker login [options] [SERVER]

Pull an image from a registry
docker pull [options] SERVER/NAME[:TAG]

Push an image to a registry
docker push SERVER/NAME[:TAG]

Save container state to a new image
docker commit CONTAINER IMAGE[:TAG]

Export an image
docker save -o PATH.tar IMAGE[:TAG]

Import an image docker load -i PATH.tar


Manage Networks

List all networks
docker network ls

Create network
docker network create --driver DRIVER NAME

Connect a container to a network
docker network connect [options] NETWORK CONTAINER

Disconnect a container from a network
docker network disconnect [options] NETWORK CONTAINER

Remove a network
docker network rm NETWORK

Remove all unused networks
docker network prune

Attach a network at container startup
docker run --network NETWORK IMAGE [COMMAND]

Manage Volumes

List all volumes
docker volume ls

Create a volume
docker volume create [options] NAME

Remove a volume
docker volume rm VOLUME

Remove all unused volumes
docker volume prune

Mount a volume at container startup
docker run --mount source=[VOLUME], target=/container/path IMAGE [COMMAND]

Mount a local folder at container startup
docker run --mount type=bind,source=/local/path,target=/container/path IMAGE [COMMAND]

Tools

Run a command in a running container
docker exec [options] CONTAINER COMMAND

Fetch the logs of a container
docker logs [-f] CONTAINER

Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

Display a live stream of container(s) resource usage statistics
docker stats

Show the history of an image
docker history IMAGE[:TAG]

Return low-level information on Docker objects
docker OBJECT_TYPE inspect OBJECT_NAME

Copy files between local system and container
docker cp /local/path CONTAINER:/container/path

Show docker disk usage
docker system df

Remove unused data
docker system prune