docker_compose.yaml 15 KB

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