docker_compose.yaml 15 KB

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