docker_compose.yaml 15 KB

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