0

I'm trying to set some environment variables for the building phase of my docker file.

This article claims that if you set an ARG and use it in ENV that ENV can be dynamically assigned and would be available to the remaining RUN commands that use bash.

This is my docker file:

ARG AuthSecret=some_auth_secret_here
ARG KeycloakClientSecret=some_keycloak_secret_here
ARG KeycloakIssuer=https://accounts.example.com/realms/Production

FROM company/custom-image:latest as builder

ENV AUTH_SECRET $AuthSecret
ENV KEYCLOAK_CLIENT_SECRET $KeycloakClientSecret
ENV KEYCLOAK_ISSUER $KeycloakIssuer

COPY . /

RUN chmod 777 /scripts/build.sh \
    && bash /scripts/build.sh

As you can see, I copy everything inside the docker image, and then run a /scripts/build.sh file.

In that file, I have this line:

echo "*************** $KEYCLOAK_CLIENT_SECRET"

And this is what I get:

"***************

In other words, the environment variables set in previous lines in the docker file are not available to my bash script.

What should I do?

Update:

Even adding this line of code does not work:

RUN echo "-------------------- $KeycloakClientSecret ---------------- $KEYCLOAK_CLIENT_SECRET"

This is the output I get:

"-------------------- ----------------

Big boy
  • 1,113
  • 2
  • 8
  • 23
  • 1
    `ARG` that appear before the first `FROM` can only be used in `FROM` lines and to provide defaults. `ARG` needs to be placed after the `FROM` line, maybe repeated in a multi-stage build, to be seen in the actual image. – David Maze Jun 26 '23 at 10:08

0 Answers0