这里是 Docker 菜鸟。
我在项目根目录有一个 docker 目录。它包含一些 docker compose 文件,例如 docker-compose-{1..5}.yml
。我想运行 docker compose up(注意:不是 docker-compose)。搜索 docker 文档、SO、互联网,我所能找到的只是运行的引用
$ 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.
我的查询是
如何使用文档中提到的使用 stringArray
中提到的单个 -f
标志一次性将多个文件传递给 docker compose
?格式是什么?
我尝试过,但没有成功:
$: 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:
我检查过这个post但它没有回答我的查询。我特别希望使用单个 -f
标志将多个字符串值(我的撰写文件路径)传递给命令 docker compose
,就像 - hey compose,我得到了这些文件,我希望您运行这些文件,而不是运行这个、运行这个、运行这个。
现在我很困惑是否有可能,或者我必须为每个文件使用多个 -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.
关于docker - 使用单个 -f 标志在 **docker compose** 中传递多个撰写文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67866470/