docker_compose_run.yaml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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: env-from-file
  105. value_type: stringArray
  106. default_value: '[]'
  107. description: Set environment variables from file
  108. deprecated: false
  109. hidden: false
  110. experimental: false
  111. experimentalcli: false
  112. kubernetes: false
  113. swarm: false
  114. - option: interactive
  115. shorthand: i
  116. value_type: bool
  117. default_value: "true"
  118. description: Keep STDIN open even if not attached
  119. deprecated: false
  120. hidden: false
  121. experimental: false
  122. experimentalcli: false
  123. kubernetes: false
  124. swarm: false
  125. - option: label
  126. shorthand: l
  127. value_type: stringArray
  128. default_value: '[]'
  129. description: Add or override a label
  130. deprecated: false
  131. hidden: false
  132. experimental: false
  133. experimentalcli: false
  134. kubernetes: false
  135. swarm: false
  136. - option: name
  137. value_type: string
  138. description: Assign a name to the container
  139. deprecated: false
  140. hidden: false
  141. experimental: false
  142. experimentalcli: false
  143. kubernetes: false
  144. swarm: false
  145. - option: no-TTY
  146. shorthand: T
  147. value_type: bool
  148. default_value: "true"
  149. description: 'Disable pseudo-TTY allocation (default: auto-detected)'
  150. deprecated: false
  151. hidden: false
  152. experimental: false
  153. experimentalcli: false
  154. kubernetes: false
  155. swarm: false
  156. - option: no-deps
  157. value_type: bool
  158. default_value: "false"
  159. description: Don't start linked services
  160. deprecated: false
  161. hidden: false
  162. experimental: false
  163. experimentalcli: false
  164. kubernetes: false
  165. swarm: false
  166. - option: publish
  167. shorthand: p
  168. value_type: stringArray
  169. default_value: '[]'
  170. description: Publish a container's port(s) to the host
  171. deprecated: false
  172. hidden: false
  173. experimental: false
  174. experimentalcli: false
  175. kubernetes: false
  176. swarm: false
  177. - option: pull
  178. value_type: string
  179. default_value: policy
  180. description: Pull image before running ("always"|"missing"|"never")
  181. deprecated: false
  182. hidden: false
  183. experimental: false
  184. experimentalcli: false
  185. kubernetes: false
  186. swarm: false
  187. - option: quiet-pull
  188. value_type: bool
  189. default_value: "false"
  190. description: Pull without printing progress information
  191. deprecated: false
  192. hidden: false
  193. experimental: false
  194. experimentalcli: false
  195. kubernetes: false
  196. swarm: false
  197. - option: remove-orphans
  198. value_type: bool
  199. default_value: "false"
  200. description: Remove containers for services not defined in the Compose file
  201. deprecated: false
  202. hidden: false
  203. experimental: false
  204. experimentalcli: false
  205. kubernetes: false
  206. swarm: false
  207. - option: rm
  208. value_type: bool
  209. default_value: "false"
  210. description: Automatically remove the container when it exits
  211. deprecated: false
  212. hidden: false
  213. experimental: false
  214. experimentalcli: false
  215. kubernetes: false
  216. swarm: false
  217. - option: service-ports
  218. shorthand: P
  219. value_type: bool
  220. default_value: "false"
  221. description: |
  222. Run command with all service's ports enabled and mapped to the host
  223. deprecated: false
  224. hidden: false
  225. experimental: false
  226. experimentalcli: false
  227. kubernetes: false
  228. swarm: false
  229. - option: tty
  230. shorthand: t
  231. value_type: bool
  232. default_value: "true"
  233. description: Allocate a pseudo-TTY
  234. deprecated: false
  235. hidden: true
  236. experimental: false
  237. experimentalcli: false
  238. kubernetes: false
  239. swarm: false
  240. - option: use-aliases
  241. value_type: bool
  242. default_value: "false"
  243. description: |
  244. Use the service's network useAliases in the network(s) the container connects to
  245. deprecated: false
  246. hidden: false
  247. experimental: false
  248. experimentalcli: false
  249. kubernetes: false
  250. swarm: false
  251. - option: user
  252. shorthand: u
  253. value_type: string
  254. description: Run as specified username or uid
  255. deprecated: false
  256. hidden: false
  257. experimental: false
  258. experimentalcli: false
  259. kubernetes: false
  260. swarm: false
  261. - option: volume
  262. shorthand: v
  263. value_type: stringArray
  264. default_value: '[]'
  265. description: Bind mount a volume
  266. deprecated: false
  267. hidden: false
  268. experimental: false
  269. experimentalcli: false
  270. kubernetes: false
  271. swarm: false
  272. - option: workdir
  273. shorthand: w
  274. value_type: string
  275. description: Working directory inside the container
  276. deprecated: false
  277. hidden: false
  278. experimental: false
  279. experimentalcli: false
  280. kubernetes: false
  281. swarm: false
  282. inherited_options:
  283. - option: dry-run
  284. value_type: bool
  285. default_value: "false"
  286. description: Execute command in dry run mode
  287. deprecated: false
  288. hidden: false
  289. experimental: false
  290. experimentalcli: false
  291. kubernetes: false
  292. swarm: false
  293. deprecated: false
  294. hidden: false
  295. experimental: false
  296. experimentalcli: false
  297. kubernetes: false
  298. swarm: false