docker_compose.yaml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. command: docker compose
  2. short: Docker Compose
  3. long: Define and run multi-container applications with Docker
  4. usage: docker compose
  5. pname: docker
  6. plink: docker.yaml
  7. cname:
  8. - docker compose attach
  9. - docker compose build
  10. - docker compose commit
  11. - docker compose config
  12. - docker compose cp
  13. - docker compose create
  14. - docker compose down
  15. - docker compose events
  16. - docker compose exec
  17. - docker compose export
  18. - docker compose images
  19. - docker compose kill
  20. - docker compose logs
  21. - docker compose ls
  22. - docker compose pause
  23. - docker compose port
  24. - docker compose ps
  25. - docker compose publish
  26. - docker compose pull
  27. - docker compose push
  28. - docker compose restart
  29. - docker compose rm
  30. - docker compose run
  31. - docker compose scale
  32. - docker compose start
  33. - docker compose stats
  34. - docker compose stop
  35. - docker compose top
  36. - docker compose unpause
  37. - docker compose up
  38. - docker compose version
  39. - docker compose wait
  40. - docker compose watch
  41. clink:
  42. - docker_compose_attach.yaml
  43. - docker_compose_build.yaml
  44. - docker_compose_commit.yaml
  45. - docker_compose_config.yaml
  46. - docker_compose_cp.yaml
  47. - docker_compose_create.yaml
  48. - docker_compose_down.yaml
  49. - docker_compose_events.yaml
  50. - docker_compose_exec.yaml
  51. - docker_compose_export.yaml
  52. - docker_compose_images.yaml
  53. - docker_compose_kill.yaml
  54. - docker_compose_logs.yaml
  55. - docker_compose_ls.yaml
  56. - docker_compose_pause.yaml
  57. - docker_compose_port.yaml
  58. - docker_compose_ps.yaml
  59. - docker_compose_publish.yaml
  60. - docker_compose_pull.yaml
  61. - docker_compose_push.yaml
  62. - docker_compose_restart.yaml
  63. - docker_compose_rm.yaml
  64. - docker_compose_run.yaml
  65. - docker_compose_scale.yaml
  66. - docker_compose_start.yaml
  67. - docker_compose_stats.yaml
  68. - docker_compose_stop.yaml
  69. - docker_compose_top.yaml
  70. - docker_compose_unpause.yaml
  71. - docker_compose_up.yaml
  72. - docker_compose_version.yaml
  73. - docker_compose_wait.yaml
  74. - docker_compose_watch.yaml
  75. options:
  76. - option: all-resources
  77. value_type: bool
  78. default_value: "false"
  79. description: Include all resources, even those not used by services
  80. deprecated: false
  81. hidden: false
  82. experimental: false
  83. experimentalcli: false
  84. kubernetes: false
  85. swarm: false
  86. - option: ansi
  87. value_type: string
  88. default_value: auto
  89. description: |
  90. Control when to print ANSI control characters ("never"|"always"|"auto")
  91. deprecated: false
  92. hidden: false
  93. experimental: false
  94. experimentalcli: false
  95. kubernetes: false
  96. swarm: false
  97. - option: compatibility
  98. value_type: bool
  99. default_value: "false"
  100. description: Run compose in backward compatibility mode
  101. deprecated: false
  102. hidden: false
  103. experimental: false
  104. experimentalcli: false
  105. kubernetes: false
  106. swarm: false
  107. - option: dry-run
  108. value_type: bool
  109. default_value: "false"
  110. description: Execute command in dry run mode
  111. deprecated: false
  112. hidden: false
  113. experimental: false
  114. experimentalcli: false
  115. kubernetes: false
  116. swarm: false
  117. - option: env-file
  118. value_type: stringArray
  119. default_value: '[]'
  120. description: Specify an alternate environment file
  121. deprecated: false
  122. hidden: false
  123. experimental: false
  124. experimentalcli: false
  125. kubernetes: false
  126. swarm: false
  127. - option: file
  128. shorthand: f
  129. value_type: stringArray
  130. default_value: '[]'
  131. description: Compose configuration files
  132. deprecated: false
  133. hidden: false
  134. experimental: false
  135. experimentalcli: false
  136. kubernetes: false
  137. swarm: false
  138. - option: no-ansi
  139. value_type: bool
  140. default_value: "false"
  141. description: Do not print ANSI control characters (DEPRECATED)
  142. deprecated: false
  143. hidden: true
  144. experimental: false
  145. experimentalcli: false
  146. kubernetes: false
  147. swarm: false
  148. - option: parallel
  149. value_type: int
  150. default_value: "-1"
  151. description: Control max parallelism, -1 for unlimited
  152. deprecated: false
  153. hidden: false
  154. experimental: false
  155. experimentalcli: false
  156. kubernetes: false
  157. swarm: false
  158. - option: profile
  159. value_type: stringArray
  160. default_value: '[]'
  161. description: Specify a profile to enable
  162. deprecated: false
  163. hidden: false
  164. experimental: false
  165. experimentalcli: false
  166. kubernetes: false
  167. swarm: false
  168. - option: progress
  169. value_type: string
  170. default_value: auto
  171. description: Set type of progress output (auto, tty, plain, json, quiet)
  172. deprecated: false
  173. hidden: false
  174. experimental: false
  175. experimentalcli: false
  176. kubernetes: false
  177. swarm: false
  178. - option: project-directory
  179. value_type: string
  180. description: |-
  181. Specify an alternate working directory
  182. (default: the path of the, first specified, Compose file)
  183. deprecated: false
  184. hidden: false
  185. experimental: false
  186. experimentalcli: false
  187. kubernetes: false
  188. swarm: false
  189. - option: project-name
  190. shorthand: p
  191. value_type: string
  192. description: Project name
  193. deprecated: false
  194. hidden: false
  195. experimental: false
  196. experimentalcli: false
  197. kubernetes: false
  198. swarm: false
  199. - option: verbose
  200. value_type: bool
  201. default_value: "false"
  202. description: Show more output
  203. deprecated: false
  204. hidden: true
  205. experimental: false
  206. experimentalcli: false
  207. kubernetes: false
  208. swarm: false
  209. - option: version
  210. shorthand: v
  211. value_type: bool
  212. default_value: "false"
  213. description: Show the Docker Compose version information
  214. deprecated: false
  215. hidden: true
  216. experimental: false
  217. experimentalcli: false
  218. kubernetes: false
  219. swarm: false
  220. - option: workdir
  221. value_type: string
  222. description: |-
  223. DEPRECATED! USE --project-directory INSTEAD.
  224. Specify an alternate working directory
  225. (default: the path of the, first specified, Compose file)
  226. deprecated: false
  227. hidden: true
  228. experimental: false
  229. experimentalcli: false
  230. kubernetes: false
  231. swarm: false
  232. examples: |-
  233. ### Use `-f` to specify the name and path of one or more Compose files
  234. Use the `-f` flag to specify the location of a Compose [configuration file](/reference/compose-file/).
  235. #### Specifying multiple Compose files
  236. You can supply multiple `-f` configuration files. When you supply multiple files, Compose combines them into a single
  237. configuration. Compose builds the configuration in the order you supply the files. Subsequent files override and add
  238. to their predecessors.
  239. For example, consider this command line:
  240. ```console
  241. $ docker compose -f compose.yaml -f compose.admin.yaml run backup_db
  242. ```
  243. The `compose.yaml` file might specify a `webapp` service.
  244. ```yaml
  245. services:
  246. webapp:
  247. image: examples/web
  248. ports:
  249. - "8000:8000"
  250. volumes:
  251. - "/data"
  252. ```
  253. If the `compose.admin.yaml` also specifies this same service, any matching fields override the previous file.
  254. New values, add to the `webapp` service configuration.
  255. ```yaml
  256. services:
  257. webapp:
  258. build: .
  259. environment:
  260. - DEBUG=1
  261. ```
  262. When you use multiple Compose files, all paths in the files are relative to the first configuration file specified
  263. with `-f`. You can use the `--project-directory` option to override this base path.
  264. Use a `-f` with `-` (dash) as the filename to read the configuration from stdin. When stdin is used all paths in the
  265. configuration are relative to the current working directory.
  266. The `-f` flag is optional. If you don’t provide this flag on the command line, Compose traverses the working directory
  267. and its parent directories looking for a `compose.yaml` or `docker-compose.yaml` file.
  268. #### Specifying a path to a single Compose file
  269. You can use the `-f` flag to specify a path to a Compose file that is not located in the current directory, either
  270. from the command line or by setting up a `COMPOSE_FILE` environment variable in your shell or in an environment file.
  271. For an example of using the `-f` option at the command line, suppose you are running the Compose Rails sample, and
  272. have a `compose.yaml` file in a directory called `sandbox/rails`. You can use a command like `docker compose pull` to
  273. get the postgres image for the db service from anywhere by using the `-f` flag as follows:
  274. ```console
  275. $ docker compose -f ~/sandbox/rails/compose.yaml pull db
  276. ```
  277. ### Use `-p` to specify a project name
  278. Each configuration has a project name. Compose sets the project name using
  279. the following mechanisms, in order of precedence:
  280. - The `-p` command line flag
  281. - The `COMPOSE_PROJECT_NAME` environment variable
  282. - The top level `name:` variable from the config file (or the last `name:`
  283. from a series of config files specified using `-f`)
  284. - The `basename` of the project directory containing the config file (or
  285. containing the first config file specified using `-f`)
  286. - The `basename` of the current directory if no config file is specified
  287. Project names must contain only lowercase letters, decimal digits, dashes,
  288. and underscores, and must begin with a lowercase letter or decimal digit. If
  289. the `basename` of the project directory or current directory violates this
  290. constraint, you must use one of the other mechanisms.
  291. ```console
  292. $ docker compose -p my_project ps -a
  293. NAME SERVICE STATUS PORTS
  294. my_project_demo_1 demo running
  295. $ docker compose -p my_project logs
  296. demo_1 | PING localhost (127.0.0.1): 56 data bytes
  297. demo_1 | 64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.095 ms
  298. ```
  299. ### Use profiles to enable optional services
  300. Use `--profile` to specify one or more active profiles
  301. Calling `docker compose --profile frontend up` starts the services with the profile `frontend` and services
  302. without any specified profiles.
  303. You can also enable multiple profiles, e.g. with `docker compose --profile frontend --profile debug up` the profiles `frontend` and `debug` is enabled.
  304. Profiles can also be set by `COMPOSE_PROFILES` environment variable.
  305. ### Configuring parallelism
  306. Use `--parallel` to specify the maximum level of parallelism for concurrent engine calls.
  307. Calling `docker compose --parallel 1 pull` pulls the pullable images defined in the Compose file
  308. one at a time. This can also be used to control build concurrency.
  309. Parallelism can also be set by the `COMPOSE_PARALLEL_LIMIT` environment variable.
  310. ### Set up environment variables
  311. You can set environment variables for various docker compose options, including the `-f`, `-p` and `--profiles` flags.
  312. Setting the `COMPOSE_FILE` environment variable is equivalent to passing the `-f` flag,
  313. `COMPOSE_PROJECT_NAME` environment variable does the same as the `-p` flag,
  314. `COMPOSE_PROFILES` environment variable is equivalent to the `--profiles` flag
  315. and `COMPOSE_PARALLEL_LIMIT` does the same as the `--parallel` flag.
  316. If flags are explicitly set on the command line, the associated environment variable is ignored.
  317. Setting the `COMPOSE_IGNORE_ORPHANS` environment variable to `true` stops docker compose from detecting orphaned
  318. containers for the project.
  319. Setting the `COMPOSE_MENU` environment variable to `false` disables the helper menu when running `docker compose up`
  320. in attached mode. Alternatively, you can also run `docker compose up --menu=false` to disable the helper menu.
  321. ### Use Dry Run mode to test your command
  322. Use `--dry-run` flag to test a command without changing your application stack state.
  323. Dry Run mode shows you all the steps Compose applies when executing a command, for example:
  324. ```console
  325. $ docker compose --dry-run up --build -d
  326. [+] Pulling 1/1
  327. ✔ DRY-RUN MODE - db Pulled 0.9s
  328. [+] Running 10/8
  329. ✔ DRY-RUN MODE - build service backend 0.0s
  330. ✔ DRY-RUN MODE - ==> ==> writing image dryRun-754a08ddf8bcb1cf22f310f09206dd783d42f7dd 0.0s
  331. ✔ DRY-RUN MODE - ==> ==> naming to nginx-golang-mysql-backend 0.0s
  332. ✔ DRY-RUN MODE - Network nginx-golang-mysql_default Created 0.0s
  333. ✔ DRY-RUN MODE - Container nginx-golang-mysql-db-1 Created 0.0s
  334. ✔ DRY-RUN MODE - Container nginx-golang-mysql-backend-1 Created 0.0s
  335. ✔ DRY-RUN MODE - Container nginx-golang-mysql-proxy-1 Created 0.0s
  336. ✔ DRY-RUN MODE - Container nginx-golang-mysql-db-1 Healthy 0.5s
  337. ✔ DRY-RUN MODE - Container nginx-golang-mysql-backend-1 Started 0.0s
  338. ✔ DRY-RUN MODE - Container nginx-golang-mysql-proxy-1 Started Started
  339. ```
  340. From the example above, you can see that the first step is to pull the image defined by `db` service, then build the `backend` service.
  341. Next, the containers are created. The `db` service is started, and the `backend` and `proxy` wait until the `db` service is healthy before starting.
  342. Dry Run mode works with almost all commands. You cannot use Dry Run mode with a command that doesn't change the state of a Compose stack such as `ps`, `ls`, `logs` for example.
  343. deprecated: false
  344. hidden: false
  345. experimental: false
  346. experimentalcli: false
  347. kubernetes: false
  348. swarm: false