Docker commands Cheat Sheet
by tobix10 via cheatography.com/27469/cs/7962/
Stored containers & images                                                             Container basics
List running containers           docker ps                                            Run in a new named            docker run -it --name cont_name #image
List all containers               docker ps -a                                         container                     #command
                                                                                       Run as a daemon               docker run -d #image #command
List images                       docker images [--tree]
                                                                                       Start container               docker start -i #container
Remove container                  docker rm #container
                                                                                       Stop container                docker stop #container
Remove image                      docker rmi #image
                                                                                       Restart container             docker restart #container
Remove all containers             docker rm `docker ps --no-trunc -aq`
Remove all images                 docker rmi `docker images -q`                        Kill container                docker kill #container
                                                                                       Run a command                 docker exec -it #container #command
#container - name or id
#image - name                                                                          #container - name or id
                                                                                       #image - name
Network                                                                                #command - e.g /bin/bash -c 'Hello World' or script.py
Run with mapped ports         docker run -d -p local_port:container_port
                                                                                       Attach/detach
                              #image #command
Show corresponding           docker port #container container_port                  Attach #1             docker attach #container
local port                                                                             Attach #2             docker start -a
                                                                                       Attach #3             docker exec -it #container bash
Files
                                                                                       Detach                CTRL-P + CTRL+Q
Map local          docker run -it --name #container -v
                                                                                       Detach shortcut works in interactive mode (run -i)
directory          /src_path:/docker_path #image #command
                                                                                       Run container in detached mode: run -itd
Copy from/to       docker cp #container src_path:dest_path
docker                                                                                 Logs & info
                                                                                       Read container stdout                      docker logs [-f] #container
Updates
                                                                                       Show running processes                     docker top #container
Update image                  docker commit -m 'desc' -a 'author' #container
                              #image:new_tag                                         Show container configuration              docker inspect #container
Add tag to image              docker tag #container #image:tag                         Show resources usage                       docker stats #container
Rename container              docker rename old_name new_name                          Show changes in filesystem                 docker diff #container
                                                                                       Show image history                         docker history #image
Update container              docker update [options] #container
configuration                                                                         Show container events                      docker events
Read about configuration options in help
                                                                                       Import & Export
Global info                                                                            Export container to tar         docker export -o file.tar #container
System-wide info                              docker info                             Import container                docker import file.tar
Version info                                   docker version                          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
                 By tobix10                                  Published 20th April, 2016.                           Sponsored by Readability-Score.com
                 cheatography.com/tobix10/                   Last updated 20th April, 2016.                        Measure your website readability!
                                                             Page 1 of 1.                                          https://readability-score.com