docker_compose_run.yaml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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] SERVICE [COMMAND] [ARGS...]
  42. pname: docker compose
  43. plink: docker_compose.yaml
  44. options:
  45. - option: build
  46. value_type: bool
  47. default_value: "false"
  48. description: Build image before starting container.
  49. deprecated: false
  50. hidden: false
  51. experimental: false
  52. experimentalcli: false
  53. kubernetes: false
  54. swarm: false
  55. - option: detach
  56. shorthand: d
  57. value_type: bool
  58. default_value: "false"
  59. description: Run container in background and print container ID
  60. deprecated: false
  61. hidden: false
  62. experimental: false
  63. experimentalcli: false
  64. kubernetes: false
  65. swarm: false
  66. - option: entrypoint
  67. value_type: string
  68. description: Override the entrypoint of the image
  69. deprecated: false
  70. hidden: false
  71. experimental: false
  72. experimentalcli: false
  73. kubernetes: false
  74. swarm: false
  75. - option: env
  76. shorthand: e
  77. value_type: stringArray
  78. default_value: '[]'
  79. description: Set environment variables
  80. deprecated: false
  81. hidden: false
  82. experimental: false
  83. experimentalcli: false
  84. kubernetes: false
  85. swarm: false
  86. - option: interactive
  87. shorthand: i
  88. value_type: bool
  89. default_value: "true"
  90. description: Keep STDIN open even if not attached.
  91. deprecated: false
  92. hidden: false
  93. experimental: false
  94. experimentalcli: false
  95. kubernetes: false
  96. swarm: false
  97. - option: label
  98. shorthand: l
  99. value_type: stringArray
  100. default_value: '[]'
  101. description: Add or override a label
  102. deprecated: false
  103. hidden: false
  104. experimental: false
  105. experimentalcli: false
  106. kubernetes: false
  107. swarm: false
  108. - option: name
  109. value_type: string
  110. description: Assign a name to the container
  111. deprecated: false
  112. hidden: false
  113. experimental: false
  114. experimentalcli: false
  115. kubernetes: false
  116. swarm: false
  117. - option: no-TTY
  118. shorthand: T
  119. value_type: bool
  120. default_value: "true"
  121. description: 'Disable pseudo-TTY allocation (default: auto-detected).'
  122. deprecated: false
  123. hidden: false
  124. experimental: false
  125. experimentalcli: false
  126. kubernetes: false
  127. swarm: false
  128. - option: no-deps
  129. value_type: bool
  130. default_value: "false"
  131. description: Don't start linked services.
  132. deprecated: false
  133. hidden: false
  134. experimental: false
  135. experimentalcli: false
  136. kubernetes: false
  137. swarm: false
  138. - option: publish
  139. shorthand: p
  140. value_type: stringArray
  141. default_value: '[]'
  142. description: Publish a container's port(s) to the host.
  143. deprecated: false
  144. hidden: false
  145. experimental: false
  146. experimentalcli: false
  147. kubernetes: false
  148. swarm: false
  149. - option: quiet-pull
  150. value_type: bool
  151. default_value: "false"
  152. description: Pull without printing progress information.
  153. deprecated: false
  154. hidden: false
  155. experimental: false
  156. experimentalcli: false
  157. kubernetes: false
  158. swarm: false
  159. - option: remove-orphans
  160. value_type: bool
  161. default_value: "false"
  162. description: Remove containers for services not defined in the Compose file.
  163. deprecated: false
  164. hidden: false
  165. experimental: false
  166. experimentalcli: false
  167. kubernetes: false
  168. swarm: false
  169. - option: rm
  170. value_type: bool
  171. default_value: "false"
  172. description: Automatically remove the container when it exits
  173. deprecated: false
  174. hidden: false
  175. experimental: false
  176. experimentalcli: false
  177. kubernetes: false
  178. swarm: false
  179. - option: service-ports
  180. value_type: bool
  181. default_value: "false"
  182. description: |
  183. Run command with the service's ports enabled and mapped to the host.
  184. deprecated: false
  185. hidden: false
  186. experimental: false
  187. experimentalcli: false
  188. kubernetes: false
  189. swarm: false
  190. - option: tty
  191. shorthand: t
  192. value_type: bool
  193. default_value: "true"
  194. description: Allocate a pseudo-TTY.
  195. deprecated: false
  196. hidden: true
  197. experimental: false
  198. experimentalcli: false
  199. kubernetes: false
  200. swarm: false
  201. - option: use-aliases
  202. value_type: bool
  203. default_value: "false"
  204. description: |
  205. Use the service's network useAliases in the network(s) the container connects to.
  206. deprecated: false
  207. hidden: false
  208. experimental: false
  209. experimentalcli: false
  210. kubernetes: false
  211. swarm: false
  212. - option: user
  213. shorthand: u
  214. value_type: string
  215. description: Run as specified username or uid
  216. deprecated: false
  217. hidden: false
  218. experimental: false
  219. experimentalcli: false
  220. kubernetes: false
  221. swarm: false
  222. - option: volume
  223. shorthand: v
  224. value_type: stringArray
  225. default_value: '[]'
  226. description: Bind mount a volume.
  227. deprecated: false
  228. hidden: false
  229. experimental: false
  230. experimentalcli: false
  231. kubernetes: false
  232. swarm: false
  233. - option: workdir
  234. shorthand: w
  235. value_type: string
  236. description: Working directory inside the container
  237. deprecated: false
  238. hidden: false
  239. experimental: false
  240. experimentalcli: false
  241. kubernetes: false
  242. swarm: false
  243. deprecated: false
  244. experimental: false
  245. experimentalcli: false
  246. kubernetes: false
  247. swarm: false