I have a Dockerfile that contains two WORKDIR
statements (amid other ones) like so:
RUN pwd # reports /root
WORKDIR /tmp
RUN wget ...
RUN tar zxvf ...
RUN cd ... && ; ./configure && make && make install
RUN sed ...
RUN sed ...
RUN rm ...
RUN rm -fr ...
WORKDIR $HOME
RUN pwd # reports /tmp (instead of /root)
I would expect pwd
to be /root
(i.e. $HOME
for root
) afterwards, but it remains at /tmp
. Am I making an obvious mistake here? Is there a better way for restoring pwd
to its "original" value.
Seems like the best way would be to explicitly set your own default value so you can be sure it's consistent, like:
ENV HOME /root
WORKDIR $HOME
.. do something in /root ..
WORKDIR /tmp
.. do something else in /tmp ..
WORKDIR $HOME
.. continue back in /root ..
Note:
The WORKDIR instruction can resolve environment variables previously set using ENV. You can only use environment variables explicitly set in the Dockerfile.
https://docs.docker.com/engine/reference/builder/#/workdir
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With