docker-compose 忽略 `configs:` 部分

docker-compose ignores `configs:` section

我有一个 docker-compose 服务定义,其配置部分如下:

# api.yml file
version: '3.3'

services:
  api:
    ...
    configs:
      - source: api_config
        target: /env.cfg

configs:
  api_config:
  file: ./config/my.cfg

当我使用此文件驱动集群时,即我使用 docker stack deploy ... 部署它时,配置文件已正确提供到 运行ning 容器中。

但是,当我尝试通过 docker-compose -f api.yml up 运行 api 的本地版本时,出现启动失败,抱怨我的 api 服务不能'找不到它的配置。 (注意:docker-compose 本身不报告任何错误。)

configs 节是否不支持普通 docker-compose 用法?

文档没有明确说明,尽管有些措辞似乎表明这仅适用于堆栈:

Note: The config must already exist or be defined in the top-level configs configuration of this stack file, or stack deployment will fail.

配置和机密是使用 swarm 模式提供的嵌入式 raft 键值存储实现的。这些功能还不适用于 运行 作为 swarm 模式的一部分的容器,因此它们将被 docker-compose 忽略。

https://docs.docker.com/engine/swarm/configs/#about-configs

Note: Docker configs are only available to swarm services, not to standalone containers. To use this feature, consider adapting your container to run as a service with a scale of 1.

是的,github issue docker compose 不支持 configs。阅读文档后,我只是浪费时间尝试它。您需要编写自定义 Dockerfile 来构建配置文件。