docker_compose.yaml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. description: Set type of progress output (auto, tty, plain, json, quiet)
  173. deprecated: false
  174. hidden: false
  175. experimental: false
  176. experimentalcli: false
  177. kubernetes: false
  178. swarm: false
  179. - option: project-directory
  180. value_type: string
  181. description: |-
  182. Specify an alternate working directory
  183. (default: the path of the, first specified, Compose file)
  184. deprecated: false
  185. hidden: false
  186. experimental: false
  187. experimentalcli: false
  188. kubernetes: false
  189. swarm: false
  190. - option: project-name
  191. shorthand: p
  192. value_type: string
  193. description: Project name
  194. deprecated: false
  195. hidden: false
  196. experimental: false
  197. experimentalcli: false
  198. kubernetes: false
  199. swarm: false
  200. - option: verbose
  201. value_type: bool
  202. default_value: "false"
  203. description: Show more output
  204. deprecated: false
  205. hidden: true
  206. experimental: false
  207. experimentalcli: false
  208. kubernetes: false
  209. swarm: false
  210. - option: version
  211. shorthand: v
  212. value_type: bool
  213. default_value: "false"
  214. description: Show the Docker Compose version information
  215. deprecated: false
  216. hidden: true
  217. experimental: false
  218. experimentalcli: false
  219. kubernetes: false
  220. swarm: false
  221. - option: workdir
  222. value_type: string
  223. description: |-
  224. DEPRECATED! USE --project-directory INSTEAD.
  225. Specify an alternate working directory
  226. (default: the path of the, first specified, Compose file)
  227. deprecated: false
  228. hidden: true
  229. experimental: false
  230. experimentalcli: false
  231. kubernetes: false
  232. swarm: false
  233. examples: |-
  234. ### Use `-f` to specify the name and path of one or more Compose files
  235. Use the `-f` flag to specify the location of a Compose [configuration file](/reference/compose-file/).
  236. #### Specifying multiple Compose files
  237. You can supply multiple `-f` configuration files. When you supply multiple files, Compose combines them into a single
  238. configuration. Compose builds the configuration in the order you supply the files. Subsequent files override and add
  239. to their predecessors.
  240. For example, consider this command line:
  241. ```console
  242. $ docker compose -f compose.yaml -f compose.admin.yaml run backup_db
  243. ```
  244. The `compose.yaml` file might specify a `webapp` service.
  245. ```yaml
  246. services:
  247. webapp:
  248. image: examples/web
  249. ports:
  250. - "8000:8000"
  251. volumes:
  252. - "/data"
  253. ```
  254. If the `compose.admin.yaml` also specifies this same service, any matching fields override the previous file.
  255. New values, add to the `webapp` service configuration.
  256. ```yaml
  257. services:
  258. webapp:
  259. build: .
  260. environment:
  261. - DEBUG=1
  262. ```
  263. When you use multiple Compose files, all paths in the files are relative to the first configuration file specified
  264. with `-f`. You can use the `--project-directory` option to override this base path.
  265. Use a `-f` with `-` (dash) as the filename to read the configuration from stdin. When stdin is used all paths in the
  266. configuration are relative to the current working directory.
  267. The `-f` flag is optional. If you don’t provide this flag on the command line, Compose traverses the working directory
  268. and its parent directories looking for a `compose.yaml` or `docker-compose.yaml` file.
  269. #### Specifying a path to a single Compose file
  270. You can use the `-f` flag to specify a path to a Compose file that is not located in the current directory, either
  271. from the command line or by setting up a `COMPOSE_FILE` environment variable in your shell or in an environment file.
  272. For an example of using the `-f` option at the command line, suppose you are running the Compose Rails sample, and
  273. have a `compose.yaml` file in a directory called `sandbox/rails`. You can use a command like `docker compose pull` to
  274. get the postgres image for the db service from anywhere by using the `-f` flag as follows:
  275. ```console
  276. $ docker compose -f ~/sandbox/rails/compose.yaml pull db
  277. ```
  278. ### Use `-p` to specify a project name
  279. Each configuration has a project name. Compose sets the project name using
  280. the following mechanisms, in order of precedence:
  281. - The `-p` command line flag
  282. - The `COMPOSE_PROJECT_NAME` environment variable
  283. - The top level `name:` variable from the config file (or the last `name:`
  284. from a series of config files specified using `-f`)
  285. - The `basename` of the project directory containing the config file (or
  286. containing the first config file specified using `-f`)
  287. - The `basename` of the current directory if no config file is specified
  288. Project names must contain only lowercase letters, decimal digits, dashes,
  289. and underscores, and must begin with a lowercase letter or decimal digit. If
  290. the `basename` of the project directory or current directory violates this
  291. constraint, you must use one of the other mechanisms.
  292. ```console
  293. $ docker compose -p my_project ps -a
  294. NAME SERVICE STATUS PORTS
  295. my_project_demo_1 demo running
  296. $ docker compose -p my_project logs
  297. demo_1 | PING localhost (127.0.0.1): 56 data bytes
  298. demo_1 | 64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.095 ms
  299. ```
  300. ### Use profiles to enable optional services
  301. Use `--profile` to specify one or more active profiles
  302. Calling `docker compose --profile frontend up` starts the services with the profile `frontend` and services
  303. without any specified profiles.
  304. You can also enable multiple profiles, e.g. with `docker compose --profile frontend --profile debug up` the profiles `frontend` and `debug` is enabled.
  305. Profiles can also be set by `COMPOSE_PROFILES` environment variable.
  306. ### Configuring parallelism
  307. Use `--parallel` to specify the maximum level of parallelism for concurrent engine calls.
  308. Calling `docker compose --parallel 1 pull` pulls the pullable images defined in the Compose file
  309. one at a time. This can also be used to control build concurrency.
  310. Parallelism can also be set by the `COMPOSE_PARALLEL_LIMIT` environment variable.
  311. ### Set up environment variables
  312. You can set environment variables for various docker compose options, including the `-f`, `-p` and `--profiles` flags.
  313. Setting the `COMPOSE_FILE` environment variable is equivalent to passing the `-f` flag,
  314. `COMPOSE_PROJECT_NAME` environment variable does the same as the `-p` flag,
  315. `COMPOSE_PROFILES` environment variable is equivalent to the `--profiles` flag
  316. and `COMPOSE_PARALLEL_LIMIT` does the same as the `--parallel` flag.
  317. If flags are explicitly set on the command line, the associated environment variable is ignored.
  318. Setting the `COMPOSE_IGNORE_ORPHANS` environment variable to `true` stops docker compose from detecting orphaned
  319. containers for the project.
  320. Setting the `COMPOSE_MENU` environment variable to `false` disables the helper menu when running `docker compose up`
  321. in attached mode. Alternatively, you can also run `docker compose up --menu=false` to disable the helper menu.
  322. ### Use Dry Run mode to test your command
  323. Use `--dry-run` flag to test a command without changing your application stack state.
  324. Dry Run mode shows you all the steps Compose applies when executing a command, for example:
  325. ```console
  326. $ docker compose --dry-run up --build -d
  327. [+] Pulling 1/1
  328. ✔ DRY-RUN MODE - db Pulled 0.9s
  329. [+] Running 10/8
  330. ✔ DRY-RUN MODE - build service backend 0.0s
  331. ✔ DRY-RUN MODE - ==> ==> writing image dryRun-754a08ddf8bcb1cf22f310f09206dd783d42f7dd 0.0s
  332. ✔ DRY-RUN MODE - ==> ==> naming to nginx-golang-mysql-backend 0.0s
  333. ✔ DRY-RUN MODE - Network nginx-golang-mysql_default Created 0.0s
  334. ✔ DRY-RUN MODE - Container nginx-golang-mysql-db-1 Created 0.0s
  335. ✔ DRY-RUN MODE - Container nginx-golang-mysql-backend-1 Created 0.0s
  336. ✔ DRY-RUN MODE - Container nginx-golang-mysql-proxy-1 Created 0.0s
  337. ✔ DRY-RUN MODE - Container nginx-golang-mysql-db-1 Healthy 0.5s
  338. ✔ DRY-RUN MODE - Container nginx-golang-mysql-backend-1 Started 0.0s
  339. ✔ DRY-RUN MODE - Container nginx-golang-mysql-proxy-1 Started Started
  340. ```
  341. 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.
  342. Next, the containers are created. The `db` service is started, and the `backend` and `proxy` wait until the `db` service is healthy before starting.
  343. 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.
  344. deprecated: false
  345. hidden: false
  346. experimental: false
  347. experimentalcli: false
  348. kubernetes: false
  349. swarm: false