Guest User

Untitled

a guest
Jan 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. # DOCKER cheatsheet
  2.  
  3. A list of commands for Docker.
  4.  
  5. ## Contents
  6.  
  7. * [General](#general)
  8. * [Image management](#image-management)
  9. * [Container information](#container-information)
  10. * [Container creation](#container-creation)
  11. * [Container management](#container-management)
  12. * [Saving containers](#saving-containers)
  13.  
  14.  
  15. ## General
  16.  
  17. List all available commands:
  18. ```sh
  19. docker
  20. ```
  21.  
  22. View the options available to a specific command:
  23. ```sh
  24. docker <subcommand> --help
  25. ```
  26.  
  27. View system-wide information about Docker;
  28. ```sh
  29. docker info
  30. ```
  31.  
  32. Clean up any resources that are dangling (not associated with a container) in addition to any stopped containers and all unused images (`-a`):
  33. ```sh
  34. docker system prune -a
  35. ```
  36.  
  37.  
  38. ## Image management
  39.  
  40. Search for an image:
  41. ```sh
  42. docker search <image>
  43. ```
  44.  
  45. Download an image:
  46. ```sh
  47. docker pull <image>
  48. ```
  49.  
  50. List all downloaded images:
  51. ```sh
  52. docker images
  53. ```
  54.  
  55. Remove an image:
  56. ```sh
  57. docker rmi <image>
  58. ```
  59.  
  60. ## Container information
  61.  
  62. Get detailed information about a container:
  63. ```sh
  64. docker inspect <container_id>
  65. ```
  66.  
  67.  
  68. Provide the statistics of a running container:
  69. ```sh
  70. docker stats <container_id>
  71. ```
  72.  
  73. See the top processes within a container:
  74. ```sh
  75. docker top <container_id>
  76. ```
  77.  
  78.  
  79. ## Container creation
  80.  
  81. Run an image:
  82. ```sh
  83. docker run <image>
  84. ```
  85.  
  86. Run an image (Ubuntu here) in a container named *myname* with access to an interactive (`-i`) shell (`-t`) that removes itself when stopped (`--rm`):
  87. ```sh
  88. docker run -it --rm --name myname ubuntu
  89. ```
  90.  
  91. Run an image and map a local directory to a container directory:
  92. ```sh
  93. docker run -v source/:dest/ <image>
  94. ```
  95.  
  96.  
  97. ## Container management
  98.  
  99. View all (`-a`) containers (active and inactive) with their size (`-s`):
  100. ```sh
  101. docker ps -as
  102. ```
  103.  
  104. Start a stopped container:
  105. ```sh
  106. docker start <container_id>
  107. ```
  108.  
  109. Stop a running container:
  110. ```sh
  111. docker stop <container_id>
  112. ```
  113.  
  114. Remove a container:
  115. ```sh
  116. docker rm <container_id>
  117. ```
  118.  
  119. Attach to a running container:
  120. ```sh
  121. docker attach <container_id>
  122. ```
  123.  
  124. Detach from an interactive shell (`-it`) inside a container:
  125. ```
  126. CTRL-p CTRL-q
  127. ```
  128.  
  129.  
  130. ## Saving containers
  131.  
  132. Commit changes to a new Docker image:
  133. ```sh
  134. docker commit -m "Commit message" -a "Author name" container_id repository/new_image_name
  135. ```
Add Comment
Please, Sign In to add comment