docker_compose_run.yaml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. command: docker compose run
  2. short: Run a one-off command on a service.
  3. long: |-
  4. Runs a one-time command against a service.
  5. the following command starts the `web` service and runs `bash` as its command:
  6. ```console
  7. $ docker compose run web bash
  8. ```
  9. Commands you use with run start in new containers with configuration defined by that of the service,
  10. including volumes, links, and other details. However, there are two important differences:
  11. First, the command passed by `run` overrides the command defined in the service configuration. For example, if the
  12. `web` service configuration is started with `bash`, then `docker compose run web python app.py` overrides it with
  13. `python app.py`.
  14. The second difference is that the `docker compose run` command does not create any of the ports specified in the
  15. service configuration. This prevents port collisions with already-open ports. If you do want the service’s ports
  16. to be created and mapped to the host, specify the `--service-ports`
  17. ```console
  18. $ docker compose run --service-ports web python manage.py shell
  19. ```
  20. Alternatively, manual port mapping can be specified with the `--publish` or `-p` options, just as when using docker run:
  21. ```console
  22. $ docker compose run --publish 8080:80 -p 2022:22 -p 127.0.0.1:2021:21 web python manage.py shell
  23. ```
  24. If you start a service configured with links, the run command first checks to see if the linked service is running
  25. and starts the service if it is stopped. Once all the linked services are running, the run executes the command you
  26. passed it. For example, you could run:
  27. ```console
  28. $ docker compose run db psql -h db -U docker
  29. ```
  30. This opens an interactive PostgreSQL shell for the linked `db` container.
  31. If you do not want the run command to start linked containers, use the `--no-deps` flag:
  32. ```console
  33. $ docker compose run --no-deps web python manage.py shell
  34. ```
  35. If you want to remove the container after running while overriding the container’s restart policy, use the `--rm` flag:
  36. ```console
  37. $ docker compose run --rm web python manage.py db upgrade
  38. ```
  39. This runs a database upgrade script, and removes the container when finished running, even if a restart policy is
  40. specified in the service configuration.
  41. usage: docker compose run [options] [-v VOLUME...] [-p PORT...] [-e KEY=VAL...] [-l
  42. KEY=VALUE...] SERVICE [COMMAND] [ARGS...]
  43. pname: docker compose
  44. plink: docker_compose.yaml
  45. options:
  46. - option: detach
  47. shorthand: d
  48. value_type: bool
  49. default_value: "false"
  50. description: Run container in background and print container ID
  51. deprecated: false
  52. hidden: false
  53. experimental: false
  54. experimentalcli: false
  55. kubernetes: false
  56. swarm: false
  57. - option: entrypoint
  58. value_type: string
  59. description: Override the entrypoint of the image
  60. deprecated: false
  61. hidden: false
  62. experimental: false
  63. experimentalcli: false
  64. kubernetes: false
  65. swarm: false
  66. - option: env
  67. shorthand: e
  68. value_type: stringArray
  69. default_value: '[]'
  70. description: Set environment variables
  71. deprecated: false
  72. hidden: false
  73. experimental: false
  74. experimentalcli: false
  75. kubernetes: false
  76. swarm: false
  77. - option: interactive
  78. shorthand: i
  79. value_type: bool
  80. default_value: "true"
  81. description: Keep STDIN open even if not attached.
  82. deprecated: false
  83. hidden: false
  84. experimental: false
  85. experimentalcli: false
  86. kubernetes: false
  87. swarm: false
  88. - option: label
  89. shorthand: l
  90. value_type: stringArray
  91. default_value: '[]'
  92. description: Add or override a label
  93. deprecated: false
  94. hidden: false
  95. experimental: false
  96. experimentalcli: false
  97. kubernetes: false
  98. swarm: false
  99. - option: name
  100. value_type: string
  101. description: Assign a name to the container
  102. deprecated: false
  103. hidden: false
  104. experimental: false
  105. experimentalcli: false
  106. kubernetes: false
  107. swarm: false
  108. - option: no-TTY
  109. shorthand: T
  110. value_type: bool
  111. default_value: "false"
  112. description: |
  113. Disable pseudo-noTty allocation. By default docker compose run allocates a TTY
  114. deprecated: false
  115. hidden: false
  116. experimental: false
  117. experimentalcli: false
  118. kubernetes: false
  119. swarm: false
  120. - option: no-deps
  121. value_type: bool
  122. default_value: "false"
  123. description: Don't start linked services.
  124. deprecated: false
  125. hidden: false
  126. experimental: false
  127. experimentalcli: false
  128. kubernetes: false
  129. swarm: false
  130. - option: publish
  131. shorthand: p
  132. value_type: stringArray
  133. default_value: '[]'
  134. description: Publish a container's port(s) to the host.
  135. deprecated: false
  136. hidden: false
  137. experimental: false
  138. experimentalcli: false
  139. kubernetes: false
  140. swarm: false
  141. - option: quiet-pull
  142. value_type: bool
  143. default_value: "false"
  144. description: Pull without printing progress information.
  145. deprecated: false
  146. hidden: false
  147. experimental: false
  148. experimentalcli: false
  149. kubernetes: false
  150. swarm: false
  151. - option: rm
  152. value_type: bool
  153. default_value: "false"
  154. description: Automatically remove the container when it exits
  155. deprecated: false
  156. hidden: false
  157. experimental: false
  158. experimentalcli: false
  159. kubernetes: false
  160. swarm: false
  161. - option: service-ports
  162. value_type: bool
  163. default_value: "false"
  164. description: |
  165. Run command with the service's ports enabled and mapped to the host.
  166. deprecated: false
  167. hidden: false
  168. experimental: false
  169. experimentalcli: false
  170. kubernetes: false
  171. swarm: false
  172. - option: tty
  173. shorthand: t
  174. value_type: bool
  175. default_value: "true"
  176. description: Allocate a pseudo-TTY.
  177. deprecated: false
  178. hidden: true
  179. experimental: false
  180. experimentalcli: false
  181. kubernetes: false
  182. swarm: false
  183. - option: use-aliases
  184. value_type: bool
  185. default_value: "false"
  186. description: |
  187. Use the service's network useAliases in the network(s) the container connects to.
  188. deprecated: false
  189. hidden: false
  190. experimental: false
  191. experimentalcli: false
  192. kubernetes: false
  193. swarm: false
  194. - option: user
  195. shorthand: u
  196. value_type: string
  197. description: Run as specified username or uid
  198. deprecated: false
  199. hidden: false
  200. experimental: false
  201. experimentalcli: false
  202. kubernetes: false
  203. swarm: false
  204. - option: volume
  205. shorthand: v
  206. value_type: stringArray
  207. default_value: '[]'
  208. description: Bind mount a volume.
  209. deprecated: false
  210. hidden: false
  211. experimental: false
  212. experimentalcli: false
  213. kubernetes: false
  214. swarm: false
  215. - option: workdir
  216. shorthand: w
  217. value_type: string
  218. description: Working directory inside the container
  219. deprecated: false
  220. hidden: false
  221. experimental: false
  222. experimentalcli: false
  223. kubernetes: false
  224. swarm: false
  225. deprecated: false
  226. experimental: false
  227. experimentalcli: false
  228. kubernetes: false
  229. swarm: false