docker_compose_run.yaml 7.3 KB

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