docker_compose_run.yaml 8.5 KB

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