docker_compose.yaml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. command: docker compose
  2. short: Docker Compose
  3. long: |-
  4. You can use compose subcommand, `docker compose [-f <arg>...] [options] [COMMAND] [ARGS...]`, to build and manage
  5. multiple services in Docker containers.
  6. ### Use `-f` to specify name and path of one or more Compose files
  7. Use the `-f` flag to specify the location of a Compose configuration file.
  8. #### Specifying multiple Compose files
  9. You can supply multiple `-f` configuration files. When you supply multiple files, Compose combines them into a single
  10. configuration. Compose builds the configuration in the order you supply the files. Subsequent files override and add
  11. to their predecessors.
  12. For example, consider this command line:
  13. ```console
  14. $ docker compose -f docker-compose.yml -f docker-compose.admin.yml run backup_db
  15. ```
  16. The `docker-compose.yml` file might specify a `webapp` service.
  17. ```yaml
  18. services:
  19. webapp:
  20. image: examples/web
  21. ports:
  22. - "8000:8000"
  23. volumes:
  24. - "/data"
  25. ```
  26. If the `docker-compose.admin.yml` also specifies this same service, any matching fields override the previous file.
  27. New values, add to the `webapp` service configuration.
  28. ```yaml
  29. services:
  30. webapp:
  31. build: .
  32. environment:
  33. - DEBUG=1
  34. ```
  35. When you use multiple Compose files, all paths in the files are relative to the first configuration file specified
  36. with `-f`. You can use the `--project-directory` option to override this base path.
  37. Use a `-f` with `-` (dash) as the filename to read the configuration from stdin. When stdin is used all paths in the
  38. configuration are relative to the current working directory.
  39. The `-f` flag is optional. If you don’t provide this flag on the command line, Compose traverses the working directory
  40. and its parent directories looking for a `compose.yaml` or `docker-compose.yaml` file.
  41. #### Specifying a path to a single Compose file
  42. You can use the `-f` flag to specify a path to a Compose file that is not located in the current directory, either
  43. from the command line or by setting up a `COMPOSE_FILE` environment variable in your shell or in an environment file.
  44. For an example of using the `-f` option at the command line, suppose you are running the Compose Rails sample, and
  45. have a `compose.yaml` file in a directory called `sandbox/rails`. You can use a command like `docker compose pull` to
  46. get the postgres image for the db service from anywhere by using the `-f` flag as follows:
  47. ```console
  48. $ docker compose -f ~/sandbox/rails/compose.yaml pull db
  49. ```
  50. ### Use `-p` to specify a project name
  51. Each configuration has a project name. If you supply a `-p` flag, you can specify a project name. If you don’t
  52. specify the flag, Compose uses the current directory name.
  53. Project name can also be set by `COMPOSE_PROJECT_NAME` environment variable.
  54. Most compose subcommand can be ran without a compose file, just passing
  55. project name to retrieve the relevant resources.
  56. ```console
  57. $ docker compose -p my_project ps -a
  58. NAME SERVICE STATUS PORTS
  59. my_project_demo_1 demo running
  60. $ docker compose -p my_project logs
  61. demo_1 | PING localhost (127.0.0.1): 56 data bytes
  62. demo_1 | 64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.095 ms
  63. ```
  64. ### Use profiles to enable optional services
  65. Use `--profile` to specify one or more active profiles
  66. Calling `docker compose --profile frontend up` will start the services with the profile `frontend` and services
  67. without any specified profiles.
  68. You can also enable multiple profiles, e.g. with `docker compose --profile frontend --profile debug up` the profiles `frontend` and `debug` will be enabled.
  69. Profiles can also be set by `COMPOSE_PROFILES` environment variable.
  70. ### Set up environment variables
  71. You can set environment variables for various docker compose options, including the `-f`, `-p` and `--profiles` flags.
  72. Setting the `COMPOSE_FILE` environment variable is equivalent to passing the `-f` flag,
  73. `COMPOSE_PROJECT_NAME` environment variable does the same for to the `-p` flag,
  74. and so does `COMPOSE_PROFILES` environment variable for to the `--profiles` flag.
  75. If flags are explicitly set on command line, associated environment variable is ignored
  76. Setting the `COMPOSE_IGNORE_ORPHANS` environment variable to `true` will stop docker compose from detecting orphaned
  77. containers for the project.
  78. usage: docker compose
  79. pname: docker
  80. plink: docker.yaml
  81. cname:
  82. - docker compose build
  83. - docker compose convert
  84. - docker compose cp
  85. - docker compose create
  86. - docker compose down
  87. - docker compose events
  88. - docker compose exec
  89. - docker compose images
  90. - docker compose kill
  91. - docker compose logs
  92. - docker compose ls
  93. - docker compose pause
  94. - docker compose port
  95. - docker compose ps
  96. - docker compose pull
  97. - docker compose push
  98. - docker compose restart
  99. - docker compose rm
  100. - docker compose run
  101. - docker compose start
  102. - docker compose stop
  103. - docker compose top
  104. - docker compose unpause
  105. - docker compose up
  106. - docker compose version
  107. clink:
  108. - docker_compose_build.yaml
  109. - docker_compose_convert.yaml
  110. - docker_compose_cp.yaml
  111. - docker_compose_create.yaml
  112. - docker_compose_down.yaml
  113. - docker_compose_events.yaml
  114. - docker_compose_exec.yaml
  115. - docker_compose_images.yaml
  116. - docker_compose_kill.yaml
  117. - docker_compose_logs.yaml
  118. - docker_compose_ls.yaml
  119. - docker_compose_pause.yaml
  120. - docker_compose_port.yaml
  121. - docker_compose_ps.yaml
  122. - docker_compose_pull.yaml
  123. - docker_compose_push.yaml
  124. - docker_compose_restart.yaml
  125. - docker_compose_rm.yaml
  126. - docker_compose_run.yaml
  127. - docker_compose_start.yaml
  128. - docker_compose_stop.yaml
  129. - docker_compose_top.yaml
  130. - docker_compose_unpause.yaml
  131. - docker_compose_up.yaml
  132. - docker_compose_version.yaml
  133. options:
  134. - option: ansi
  135. value_type: string
  136. default_value: auto
  137. description: |
  138. Control when to print ANSI control characters ("never"|"always"|"auto")
  139. deprecated: false
  140. experimental: false
  141. experimentalcli: false
  142. kubernetes: false
  143. swarm: false
  144. - option: compatibility
  145. value_type: bool
  146. default_value: "false"
  147. description: Run compose in backward compatibility mode
  148. deprecated: false
  149. experimental: false
  150. experimentalcli: false
  151. kubernetes: false
  152. swarm: false
  153. - option: env-file
  154. value_type: string
  155. description: Specify an alternate environment file.
  156. deprecated: false
  157. experimental: false
  158. experimentalcli: false
  159. kubernetes: false
  160. swarm: false
  161. - option: file
  162. shorthand: f
  163. value_type: stringArray
  164. default_value: '[]'
  165. description: Compose configuration files
  166. deprecated: false
  167. experimental: false
  168. experimentalcli: false
  169. kubernetes: false
  170. swarm: false
  171. - option: no-ansi
  172. value_type: bool
  173. default_value: "false"
  174. description: Do not print ANSI control characters (DEPRECATED)
  175. deprecated: false
  176. experimental: false
  177. experimentalcli: false
  178. kubernetes: false
  179. swarm: false
  180. - option: profile
  181. value_type: stringArray
  182. default_value: '[]'
  183. description: Specify a profile to enable
  184. deprecated: false
  185. experimental: false
  186. experimentalcli: false
  187. kubernetes: false
  188. swarm: false
  189. - option: project-directory
  190. value_type: string
  191. description: |-
  192. Specify an alternate working directory
  193. (default: the path of the Compose file)
  194. deprecated: false
  195. experimental: false
  196. experimentalcli: false
  197. kubernetes: false
  198. swarm: false
  199. - option: project-name
  200. shorthand: p
  201. value_type: string
  202. description: Project name
  203. deprecated: false
  204. experimental: false
  205. experimentalcli: false
  206. kubernetes: false
  207. swarm: false
  208. - option: verbose
  209. value_type: bool
  210. default_value: "false"
  211. description: Show more output
  212. deprecated: false
  213. experimental: false
  214. experimentalcli: false
  215. kubernetes: false
  216. swarm: false
  217. - option: version
  218. shorthand: v
  219. value_type: bool
  220. default_value: "false"
  221. description: Show the Docker Compose version information
  222. deprecated: false
  223. experimental: false
  224. experimentalcli: false
  225. kubernetes: false
  226. swarm: false
  227. - option: workdir
  228. value_type: string
  229. description: |-
  230. DEPRECATED! USE --project-directory INSTEAD.
  231. Specify an alternate working directory
  232. (default: the path of the Compose file)
  233. deprecated: false
  234. experimental: false
  235. experimentalcli: false
  236. kubernetes: false
  237. swarm: false
  238. deprecated: false
  239. experimental: false
  240. experimentalcli: false
  241. kubernetes: false
  242. swarm: false