0

我有以下 docker 命令:

sudo docker run --env-file env.list \
  -p 80:8080 \
  -v $PWD/snowplow/config:/snowplow/config  \
  snowplow/scala-stream-collector-kinesis:1.0.0  \
  --config /snowplow/config/config.hocon

我正在尝试将其移动到一个docker-compose.yml文件中,但我遇到了 --config 选项的问题。我的文件看起来像这样,任何人都可以看到我哪里出错了:

version: '3.3'
services:
  collector:
    image: snowplow/scala-stream-collector-kinesis:1.0.0
    environment:
      - AWS_CBOR_DISABLE=1
    ports:
      - "80:8080"
    volumes:                                                                                                  
      - ./data/snowplow:/snowplow
    configs:
      - source: collectorcnf                                                                                    
        target: /snowplow/config/config.hocon          
configs:
  collectorcnf:
    file: ./data/snowplow/config/config.hocon

我已经相应地移动了配置文件以匹配。我收到的错误消息sudo docker-compose up是:

collector_1  | Error: Missing option --config
collector_1  | Try --help for more information.
collector_1  | configuration has no "collector" path
4

2 回答 2

3

出现在图像名称之后的所有内容都将覆盖图像默认命令。所以你要:

version: '3.3'
services:
  collector:
    image: snowplow/scala-stream-collector-kinesis:1.0.0
    # the below "command" is the portion after the image name in the run command:
    command: ["--config", "/snowplow/config/config.hocon"]
    environment:
      - AWS_CBOR_DISABLE=1
    ports:
      - "80:8080"
    volumes:
      - ./data/snowplow:/snowplow

当图像定义了入口点时,命令会附加在入口点之后以成为命令的参数。使用 json 格式对于避免将其包含在/bin/sh -c "..."语法中很重要。

于 2020-04-10T17:50:26.600 回答
2

显然,--configwith dockercommand 和configsin docker-composepoint 是两个不同的东西。

configscompose 文件中的选项docker config用于设置服务配置。在此处查看更多详细信息。这在docker swarm运行 docker 服务时可以很好地发挥作用。

另一方面,该--config选项专门用于 docker 客户端配置,即目录下的文件.docker。更多细节在这里

注意:我明白为什么这个命名非常令人困惑。docker-compose up运行时会发出警告configs,提示configs如下 - 摘录如下(基于您的collector标签):

WARNING: Some services (collector) use the 'configs' key, which will be ignored. Compose does not support 'configs' configuration - use `docker stack deploy` to deploy to a swarm.
于 2020-04-10T17:48:22.570 回答