Search code examples
dockerdocker-composesnowplow

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

Solution

  • 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.