0
FROM node:latest

ARG TEST_ARG
ENV TEST_ENV=0

RUN if [ "$DOES_NOT_EXIST" != "" ] ; then echo "Setting" ; TEST_ENV=$TEST_ARG ; fi

RUN echo $TEST_ENV

I can't seem to set the ENV variable at runtime. It persists at showing 0. TEST_ARG is working as it should, I've checked this.

basickarl
  • 37,187
  • 64
  • 214
  • 335
  • Possible duplicate of [Conditional ENV in Dockerfile](https://stackoverflow.com/questions/37057468/conditional-env-in-dockerfile) – basickarl Feb 22 '18 at 16:52
  • Each `RUN` statement is run in a separate layer, that is why `TEST_ENV=$TEST_ARG` will work within that `RUN` command only and won't persist. See my answer at [Conditional ENV in Dockerfile](https://stackoverflow.com/a/51264575/447249) for possible solution. – Ruslan Kabalin Jul 10 '18 at 12:11

0 Answers0