Is there a way to enable a directive of the form
ENV SOMEVAR=SOMEVALUE
...at build time, e.g. through some docker buildx build
command-line flag, or through some the setting of some environment variable (in the docker buildx build
process's environment)?
Alternatively, is there some way that I can modify the value that gets assigned in the ENV
on the basis of some setting (flag, environment variable, etc.) at build time?
I suppose I could do something like
RUN <<EOF
#!/usr/bin/env bash
if [[ -n $SOMEVAR ]];
printf -- "\n\nexport SOMEVAR='%s'\n\n" "$SOMEVAR" >> /root/.bashrc
fi
EOF
...and then, at build time, include the flag --build-arg "SOMEVAR=SOMEVALUE"
in the docker buildx build
command line to have the printf
line executed during the build, but such maneuvers strike me as extremely fragile. Plus, I doubt that this comes even close to replicating the effect of the original ENV SOMEVAR=SOMEVALUE
directive.
Is there a better way?