docker - 使用单个 -f 标志在 **docker compose** 中传递多个撰写文件

标签 docker docker-compose

这里是 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.

来源:https://docs.docker.com/compose/reference/envvars/

关于docker - 使用单个 -f 标志在 **docker compose** 中传递多个撰写文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67866470/

相关文章:

python - 获取 flake8 返回非零代码 : 1 in docker

python - docker中的ngrok无法连接到Django开发服务器

apache - 如何以非 root 用户身份运行 Apache?

带有自动 SSL 的 .NET Core Docker

docker - 通过SqlAlchemy从Docker容器创建与Oracle自主数据库的连接

docker - 如何使用 wget 而不是 curl 进行 Docker 健康检查?

java - 从主机使用 Java 共享堆空间

docker - docker:将docker命令转换为docker-compose语法

node.js - 如何在 Dockerfile 中执行 2 个单独的命令?

mysql - 在 OSX 中挂载 Docker 卷时权限被拒绝