JSON string interpolation from argument in Dockerfile

Viewed 1660
ARG consumer-key
ARG consumer-secret

ENV COMPOSER_AUTH '{ "bitbucket-oauth": { "bitbucket.org": { "consumer-key": "${consumer-key}", "consumer-secret": "${consumer-secret}" } } }'
docker build \
--build-arg consumer-key=test \
--build-arg consumer-secret=test \
.

The values of consumer-key and consumer-secret are not replaced with the build arguments

1 Answers

To begin with, please rename your arguments using underscores:

ARG consumer_key
ARG consumer_secret

Then, using single quotes around the argument variables properly interpolates them into the string:

ENV COMPOSER_AUTH '{ "bitbucket-oauth": { "bitbucket.org": { "consumer-key": "'$consumer_key'", "consumer-secret": "'$consumer_secret'" } } }'

Finally, change your docker build command accordingly:

docker build \
--build-arg consumer_key=test \
--build-arg consumer_secret=test \
.
Related