Show Menu

Docker commands Cheat Sheet by

docker

Stored containers & images

List running containers
docker ps
List all containers
docker ps -a
List images
docker images [--tree]
Remove container
docker rm #container
Remove image
docker rmi #image
Remove all containers
docker rm `docker ps --no-trunc -aq`
Remove all images
docker rmi `docker images -q`
#container - name or id
#image - name

Network

Run with mapped ports
docker run -d -p local_­por­t:c­ont­ain­er_port #image #command
Show corres­ponding local port
docker port #container contai­ner­_port

Files

Map local directory
docker run -it --name #container -v /src_p­ath­:/d­ock­er_path #image #command
Copy from/to docker
docker cp #container src_pa­th:­des­t_path

Updates

Update image
docker commit -m 'desc' -a 'author' #container #image­:ne­w_tag
Add tag to image
docker tag #container #image:tag
Rename container
docker rename old_name new_name
Update container config­uration
docker update [options] #container
Read about config­uration options in help

Global info

System­-wide info
docker info
Version info
docker version
 

Container basics

Run in a new named container
docker run -it --name cont_name #image #command
Run as a daemon
docker run -d #image #command
Start container
docker start -i #container
Stop container
docker stop #container
Restart container
docker restart #container
Kill container
docker kill #container
Run a command
docker exec -it #container #command
#container - name or id
#image - name
#command - e.g /bin/bash -c 'Hello World' or script.py

Attach­/detach

Attach #1
docker attach #container
Attach #2
docker start -a
Attach #3
docker exec -it #container bash
Detach
CTRL-P + CTRL+Q
Detach shortcut works in intera­ctive mode (run -i)
Run container in detached mode: run -itd

Logs & info

Read container stdout
docker logs [-f] #container
Show running processes
docker top #container
Show container config­uration
docker inspect #container
Show resources usage
docker stats #container
Show changes in filesystem
docker diff #container
Show image history
docker history #image
Show container events
docker events

Import & Export

Export container to tar
docker export -o file.tar #container
Import container
docker import file.tar
Export image to tar
docker save -o file.tar #image­[:tag]
Import image
docker load -i file.tar

Help

Command help
docker #command --help
#command - name e.g attach, ps

Download the Docker commands Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/tobix10_docker-commands.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

TME520 TME520, 01:24 27 Apr 16

Saved me a lot of time today, good work.

phedro phedro, 08:56 22 Feb 19

handy thanks. I knew the concepts, but not how to do it

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          docker-compose Cheat Sheet
          Docker OSX use Cheat Sheet