home
docker cheat sheet
Software container platform
print

docker version: 17.09+ - Date: October 2017

Installation

From Linux shell
curl -fsSL https://get.docker.com/ | sh

Show the Docker version information
docker version

Start containers

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

Run a container in background
docker run -d IMAGE [COMMAND]

Manage containers

List running containers
docker ps

List all containers
docker ps -a

Restart container
docker restart [options] CONTAINER

Stop a running container
docker stop CONTAINER

Remove a container
docker rm 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 [options] IMAGE[:TAG]

List all local images
docker images

Remove an image
docker rmi [options] [IMAGE]

Remove all images
docker rmi $(docker images -q)

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 an image
docker commit [options] CONTAINER [REPOSITORY[: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 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 [options] 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 inspect OBJECT/CONTAINER

Attach local standard input, output, and error streams to a running container
docker attach [options] CONTAINER

Display system-wide information
docker info

Show docker disk usage
docker system df

Remove unused data
docker system prune