docker_compose_run.yaml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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
  42. KEY=VALUE...] SERVICE [COMMAND] [ARGS...]
  43. pname: docker compose
  44. plink: docker_compose.yaml
  45. options:
  46. - option: detach
  47. shorthand: d
  48. value_type: bool
  49. default_value: "false"
  50. description: Run container in background and print container ID
  51. deprecated: 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. experimental: false
  61. experimentalcli: false
  62. kubernetes: false
  63. swarm: false
  64. - option: env
  65. shorthand: e
  66. value_type: stringArray
  67. default_value: '[]'
  68. description: Set environment variables
  69. deprecated: false
  70. experimental: false
  71. experimentalcli: false
  72. kubernetes: false
  73. swarm: false
  74. - option: labels
  75. shorthand: l
  76. value_type: stringArray
  77. default_value: '[]'
  78. description: Add or override a label
  79. deprecated: false
  80. experimental: false
  81. experimentalcli: false
  82. kubernetes: false
  83. swarm: false
  84. - option: name
  85. value_type: string
  86. description: Assign a name to the container
  87. deprecated: false
  88. experimental: false
  89. experimentalcli: false
  90. kubernetes: false
  91. swarm: false
  92. - option: no-TTY
  93. shorthand: T
  94. value_type: bool
  95. default_value: "false"
  96. description: |
  97. Disable pseudo-noTty allocation. By default docker compose run allocates a TTY
  98. deprecated: false
  99. experimental: false
  100. experimentalcli: false
  101. kubernetes: false
  102. swarm: false
  103. - option: no-deps
  104. value_type: bool
  105. default_value: "false"
  106. description: Don't start linked services.
  107. deprecated: false
  108. experimental: false
  109. experimentalcli: false
  110. kubernetes: false
  111. swarm: false
  112. - option: publish
  113. shorthand: p
  114. value_type: stringArray
  115. default_value: '[]'
  116. description: Publish a container's port(s) to the host.
  117. deprecated: false
  118. experimental: false
  119. experimentalcli: false
  120. kubernetes: false
  121. swarm: false
  122. - option: rm
  123. value_type: bool
  124. default_value: "false"
  125. description: Automatically remove the container when it exits
  126. deprecated: false
  127. experimental: false
  128. experimentalcli: false
  129. kubernetes: false
  130. swarm: false
  131. - option: service-ports
  132. value_type: bool
  133. default_value: "false"
  134. description: |
  135. Run command with the service's ports enabled and mapped to the host.
  136. deprecated: false
  137. experimental: false
  138. experimentalcli: false
  139. kubernetes: false
  140. swarm: false
  141. - option: use-aliases
  142. value_type: bool
  143. default_value: "false"
  144. description: |
  145. Use the service's network useAliases in the network(s) the container connects to.
  146. deprecated: false
  147. experimental: false
  148. experimentalcli: false
  149. kubernetes: false
  150. swarm: false
  151. - option: user
  152. shorthand: u
  153. value_type: string
  154. description: Run as specified username or uid
  155. deprecated: false
  156. experimental: false
  157. experimentalcli: false
  158. kubernetes: false
  159. swarm: false
  160. - option: volume
  161. shorthand: v
  162. value_type: stringArray
  163. default_value: '[]'
  164. description: Bind mount a volume.
  165. deprecated: false
  166. experimental: false
  167. experimentalcli: false
  168. kubernetes: false
  169. swarm: false
  170. - option: workdir
  171. shorthand: w
  172. value_type: string
  173. description: Working directory inside the container
  174. deprecated: false
  175. experimental: false
  176. experimentalcli: false
  177. kubernetes: false
  178. swarm: false
  179. deprecated: false
  180. experimental: false
  181. experimentalcli: false
  182. kubernetes: false
  183. swarm: false