I have exported the variables to make sure that even in a new instance of the shell the variable is persisted but it doesn't work... I don't know how I should do it. I've done a lot of research and testing, nothing conclusive.
Dockerfile:
FROM bitnami/minideb:stretch
SHELL ["/bin/bash", "-c"]
ARG VAR1="1"
ARG VAR2="Hello"
# Export arguments
RUN export VAR1="${VAR1}" \
&& export VAR2="${VAR2}"
# Output "Hello world"
RUN if [ $VAR1 = "1" ]; then VAR2+=" world"; fi \
&& echo $VAR2
# Output "Hello" instead of "Hello World"
RUN echo $VAR2
For sure each RUN
happens in a new shell.
But why the heck VAR2+=" world"
is not persisted since export VAR2="${VAR2}
is persisted?
I really don't get it.
Thanks in advance to anyone who finds a way to tackle this odd behaviour.