Passing multiple compose files in **docker compose** using single -f flag

Viewed 809

Docker noob here.

I have a docker directory at project root. It contains some docker compose files, say, docker-compose-{1..5}.yml. I want to run docker compose up (Note: not docker-compose). Searching docker documentation, SO, Internet, all I can find is references to run as in

$ project_root/docker: docker-compose -f docker-compose-1.yml -f docker-compose-2.yml -f docker-compose-2.yml up 

However, while trying help doc for docker compose shows

$: docker compose --help

Usage:  docker compose [OPTIONS] COMMAND

Docker Compose

Options:
      --ansi string                Control when to print ANSI control characters ("never"|"always"|"auto") (default "auto")
      --env-file string            Specify an alternate environment file.
  -f, --file stringArray           Compose configuration files
      --profile stringArray        Specify a profile to enable
      --project-directory string   Specify an alternate working directory
                                   (default: the path of the Compose file)
  -p, --project-name string        Project name

Commands:
  build       Build or rebuild services
  .
  .
  .
  up          Create and start containers

Run 'docker compose COMMAND --help' for more information on a command.

MY QUERY IS

How to pass multiple files to docker compose in one go using single -f flag as mentioned in doc using stringArray? What is the format?

I tried, but no success:

$: docker compose -f "file1.yml" "file2.yml" up   # nope
 
$: docker compose -f ["file1.yml" "file2.yml"] up   # nope 

$: docker compose -f ["file1.yml", "file2.yml"] up   #nope

$: docker compose -f {"file1.yml" "file2.yml"} up   #nope

$: docker compose -f ("file1.yml" "file2.yml") up   #nope

# and some other combinations thereof.

EDIT#1:

I had checked this post but it does not answer my query. I am specifically looking for passing multiple string values (my compose files path) to the command docker compose using a single -f flag, much like - hey compose, I got these files and I want you to run these rather than run this, run this, run this.

Now I am confused if it is even possible or I have to use multiple -f one for each file. But the help doc should not mention then

Usage:  docker compose [OPTIONS] COMMAND

Docker Compose

Options:
  -f, --file stringArray           Compose configuration files  # <-- It says files here
1 Answers

You can try using the COMPOSE_FILE environment variable while specifying multiple compose files in it:

COMPOSE_FILE
Specify the path to a Compose file. If not provided, Compose looks for a file named docker-compose.yml in the current directory and then each parent directory in succession until a file by that name is found.

This variable supports multiple Compose files separated by a path separator (on Linux and macOS the path separator is :, on Windows it is ;). For example: COMPOSE_FILE=docker-compose.yml:docker-compose.prod.yml. The path separator can also be customized using COMPOSE_PATH_SEPARATOR.

Source: https://docs.docker.com/compose/reference/envvars/

Related