简体   繁体   中英

How do I apply a docker run with --config option to docker compose

I have the following docker command:

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

I'm trying to move this into a docker-compose.yml file but I'm having issues with the --config option. My file looks like this, can anyone see where I am going wrong:

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

I've moved the config file accordingly to match. The error message I am getting on sudo docker-compose up is:

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

Everything that appears after an image name is overriding the image default command. So you want:

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

When an image has an entrypoint defined, the command is appended after the entrypoint to become arguments to the command. Using json formatting is important to avoid this being wrapped in a /bin/sh -c "..." syntax.

Apparently, the --config with the docker command and configs in docker-compose point two separate things.

The configs option in the compose file is for docker config which is used for setting service config. See more details here . This plays nicely with docker swarm and while running docker services.

On the other hand, the --config option is specifically for the docker client config ie the file under .docker directory. More details here .

Note: I can see why this naming is super confusing. There is a warning issued when you run docker-compose up with configs which hints at configs - excerpt below (based on your collector tag):

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM