docker - 使用单个 -f 标志在 **docker compose** 中传递多个撰写文件
问题描述
Docker 菜鸟在这里。
我在项目根目录有一个 docker 目录。它包含一些 docker compose 文件,例如docker-compose-{1..5}.yml
. 我想跑docker compose up
(注:不是docker-compose
)。搜索 docker 文档、SO、Internet,我能找到的只是运行参考
$ project_root/docker: docker-compose -f docker-compose-1.yml -f docker-compose-2.yml -f docker-compose-2.yml up
但是,在尝试帮助文档进行docker compose
节目时
$: 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.
我的问题是
如何使用doc using 中提到的docker compose
单个标志一次性传递多个文件?格式是什么?-f
stringArray
我试过了,但没有成功:
$: 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.
编辑#1:
我已经检查了这篇文章,但它没有回答我的查询。我专门寻找docker compose
使用单个-f
标志将多个字符串值(我的撰写文件路径)传递给命令,就像 -嘿撰写,我得到了这些文件,我希望你运行这些而不是运行这个,运行这个,运行这个.
现在我很困惑是否有可能,或者我必须-f
为每个文件使用多个。但是帮助文档不应该提及
Usage: docker compose [OPTIONS] COMMAND
Docker Compose
Options:
-f, --file stringArray Compose configuration files # <-- It says files here
解决方案
您可以尝试使用COMPOSE_FILE
环境变量,同时在其中指定多个撰写文件:
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.