Docker Cheat Sheet & Quick ReferenceMobile visit

Image

$ docker build -t my-image:1.0 .

Build a image with the name my-image and tag 1.0

$ docker image ls

List local images

$ docker image rm my-image:1.0

Delete local image by the name:tag my-image:1.0

$ docker build -t my-image .

Build an image in the current directory with the name my-image

$ docker pull nginx
$ docker image pull nginx #version >= 1.13

Pull image nginx from a registry

$ docker push myrepo/my-image:2.0
$ docker image push myrepo/my-image:2.0 #version >= 1.13

Push image my-image to repository myrepo under a registry

Container

$ docker run my-image:1.0
$ docker container run my-image:1.0 #version >= 1.13

Run a container from my-image:1.0

$ docker run --name www my-image:1.0

Run a container from my-image:1.0 with the name www

$ docker run --name www -p 80:3000 my-image:1.0

Run a container from my-image:1.0 exposing internal port 3000 to external port 80

$ docker stop www
$ docker container stop www #version >= 1.13

Stop a container by the name www

$ docker stop www1 www2
$ docker container stop www1 www2 #version >= 1.13

Stop containers by the name www1 www2 ...

$ docker kill www
$ docker container kill www #version >= 1.13

Kill a container by the name www

$ docker kill www1 www2
$ docker container kill www1 www2 #version >= 1.13

Kill containers by the name www1 www2 ...

$ docker ps
$ docker container list #version >= 1.13
$ docker container ls #version >= 1.13

List running containers

$ docker ps --all
$ docker ps -a
$ docker container list --all #version >= 1.13
$ docker container ls -all #version >= 1.13

List all containers

$ docker exec www id
$ docker container exec www id #version >= 1.13

Runs id in www container

$ docker exec -it ubuntu bash
$ docker container exec -it ubuntu bash #version >= 1.13

Run an interactive bash shell on the container

Network

$ docker network ls #version >= 1.21

List network

System

$ docker system prune # version >= 1.25

Remove all unused containers, networks, images (both dangling and unreferenced)

$ docker system prune --volumes # version >= 1.25

Remove all unused containers, networks, images (both dangling and unreferenced), and volumes.

$ docker system prune --all --volumes # version >= 1.25

Remove all unused containers, networks, all unused images, and volumes.

Compose

$ docker-compose up

Create and run containers in the foreground

$ docker-compose up -d

Create and run containers in the background

$ docker-compose ps

List running containers

$ docker-compose ps --all
$ docker-compose ps -a

List all containers

$ docker-compose stop

Stop containers

$ docker-compose down

Stop and remove containers, networks created by up

$ docker-compose pull

Pull images defined in a Compose file