Reputation: 558
Is it possible to use envsubst with build-arg during build time of the docker image ? I have a following scenario:
FROM alpine as substitutor
ARG ROOT_PWD
RUN apk add --no-cache envsubst
WORKDIR /app
COPY ./myfile.json .
RUN export ROOT_PASSWORD=${ROOT_PWD} && \
envsubst < myfile.json
But it doesn't seem to be working. any ideas ?
Upvotes: 0
Views: 1099
Reputation: 26285
I suspect you are using DOCKER_BUILDKIT
, in which case by default the output is not shown.
You can either disable DOCKER_BUILDKIT
or you can change the progress output.
So given:
$ cat myfile.json
echo "$ROOT_PASSWORD"
and Dockerfile:
FROM alpine as substitutor
ARG ROOT_PWD
RUN apk add --no-cache envsubst
WORKDIR /app
COPY ./myfile.json .
RUN export ROOT_PASSWORD=${ROOT_PWD} && \
envsubst < myfile.json
Disabling DOCKER_BUILDKIT
:
$ DOCKER_BUILDKIT=0 docker build --no-cache -t foo --build-arg ROOT_PWD=foo .
...
Step 6/6 : RUN export ROOT_PASSWORD=${ROOT_PWD} && envsubst < myfile.json
---> Running in 392f9f557efc
echo "foo"
...
Using --progress=plain
:
$ docker build --progress=plain --no-cache -t foo --build-arg ROOT_PWD=bar .
...
#9 [5/5] RUN export ROOT_PASSWORD=foob && envsubst < myfile.json
#9 sha256:11149db43acce77a19337f355e010081c758738bae15daa2c4ddf8405e85c7c7
#9 0.559 echo "bar"
#9 DONE 0.6s
...
Upvotes: 1
Reputation: 2709
Your issue is that you're reading the file myfile.json
but you're not writing the output. So you need to change your envsubst
command to be redirected to an output file like this:
RUN export ROOT_PASSWORD=${ROOT_PWD} && envsubst < myfile.json > myfile-out.json
Upvotes: 0