Docker Community Forums

Share and learn in the Docker community.

Multistage build using a file for variable

In a multistage build, I write a variable to file.txt and copy it to the next stage. I see the file.txt, source it and make it available to the image, but can not add it to path. Thank you :).

file.txt
P=/path/to/use

RUN source file.txt \
    && echo ${P} \
    && echo export PATH='$PATH:$P' >> /root/.bashrc

what error are you seeing?
have you tried using " instead of ’ around your path variables?

I do not get an error and the image builds successfully… I just can not use the variable in file.txt in 'echo export PATH='$PATH:$P' >> /root/.bashrc. I have tied " and ', the issue seems to be the file is not available to use in the image.
I know if I did from build the variable would be available … the problem is I have another FROM statement to use after that and the variable is not available to use. Thank you :).

FROM build ---- variable can be used -----

when another FROM id added I can not use the variable in it… I did try COPY=from build / / but that did not work.