pwas
pwas

Reputation: 3373

Docker - pass argumens to service with docker compose up

Consider I have docker-compose.yaml:

my-service:
    build:
        context: my-service/.
        args:
        - http_proxy
        - https_proxy
    command: -my-some-argument 100 %CONSUMER_ARGS%
    networks:
        - custom-network

docker-compose.yaml is called via shell:

> docker-compose up

Argument my-some-argument is passed to container properly. But somehow, environment variable %CONSUMER_ARGS% is not replaced with proper value (literal string %CONSUMER_ARGS% is passed to container). So is there other way to pass arguments to my container while calling docker-compose up? Dokcer is running windows, containers under linux images.

Upvotes: 1

Views: 100

Answers (2)

kamal sehrawat
kamal sehrawat

Reputation: 131

Your templating syntax for env variable replacement is not correct. Use

${ENV_PASSED_VALUE:-DEFAULT_VALUE}

Upvotes: 0

giskou
giskou

Reputation: 850

You can use environmental variables in compose like this:

my-service:
    build:
        context: my-service/.
        args:
        - http_proxy
        - https_proxy
    command: -my-some-argument 100 ${CONSUMER_ARGS}
    networks:
        - custom-network

Note the ${} instead of %%

More info here: https://docs.docker.com/compose/environment-variables/

Upvotes: 2

Related Questions