docker_compose_run.yaml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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
  188. shorthand: q
  189. value_type: bool
  190. default_value: "false"
  191. description: Don't print anything to STDOUT
  192. deprecated: false
  193. hidden: false
  194. experimental: false
  195. experimentalcli: false
  196. kubernetes: false
  197. swarm: false
  198. - option: quiet-build
  199. value_type: bool
  200. default_value: "false"
  201. description: Suppress progress output from the build process
  202. deprecated: false
  203. hidden: false
  204. experimental: false
  205. experimentalcli: false
  206. kubernetes: false
  207. swarm: false
  208. - option: quiet-pull
  209. value_type: bool
  210. default_value: "false"
  211. description: Pull without printing progress information
  212. deprecated: false
  213. hidden: false
  214. experimental: false
  215. experimentalcli: false
  216. kubernetes: false
  217. swarm: false
  218. - option: remove-orphans
  219. value_type: bool
  220. default_value: "false"
  221. description: Remove containers for services not defined in the Compose file
  222. deprecated: false
  223. hidden: false
  224. experimental: false
  225. experimentalcli: false
  226. kubernetes: false
  227. swarm: false
  228. - option: rm
  229. value_type: bool
  230. default_value: "false"
  231. description: Automatically remove the container when it exits
  232. deprecated: false
  233. hidden: false
  234. experimental: false
  235. experimentalcli: false
  236. kubernetes: false
  237. swarm: false
  238. - option: service-ports
  239. shorthand: P
  240. value_type: bool
  241. default_value: "false"
  242. description: |
  243. Run command with all service's ports enabled and mapped to the host
  244. deprecated: false
  245. hidden: false
  246. experimental: false
  247. experimentalcli: false
  248. kubernetes: false
  249. swarm: false
  250. - option: tty
  251. shorthand: t
  252. value_type: bool
  253. default_value: "true"
  254. description: Allocate a pseudo-TTY
  255. deprecated: false
  256. hidden: true
  257. experimental: false
  258. experimentalcli: false
  259. kubernetes: false
  260. swarm: false
  261. - option: use-aliases
  262. value_type: bool
  263. default_value: "false"
  264. description: |
  265. Use the service's network useAliases in the network(s) the container connects to
  266. deprecated: false
  267. hidden: false
  268. experimental: false
  269. experimentalcli: false
  270. kubernetes: false
  271. swarm: false
  272. - option: user
  273. shorthand: u
  274. value_type: string
  275. description: Run as specified username or uid
  276. deprecated: false
  277. hidden: false
  278. experimental: false
  279. experimentalcli: false
  280. kubernetes: false
  281. swarm: false
  282. - option: volume
  283. shorthand: v
  284. value_type: stringArray
  285. default_value: '[]'
  286. description: Bind mount a volume
  287. deprecated: false
  288. hidden: false
  289. experimental: false
  290. experimentalcli: false
  291. kubernetes: false
  292. swarm: false
  293. - option: workdir
  294. shorthand: w
  295. value_type: string
  296. description: Working directory inside the container
  297. deprecated: false
  298. hidden: false
  299. experimental: false
  300. experimentalcli: false
  301. kubernetes: false
  302. swarm: false
  303. inherited_options:
  304. - option: dry-run
  305. value_type: bool
  306. default_value: "false"
  307. description: Execute command in dry run mode
  308. deprecated: false
  309. hidden: false
  310. experimental: false
  311. experimentalcli: false
  312. kubernetes: false
  313. swarm: false
  314. deprecated: false
  315. hidden: false
  316. experimental: false
  317. experimentalcli: false
  318. kubernetes: false
  319. swarm: false