docker_compose.yaml 15 KB

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