我有一个包含两个 WORKDIR
的 Dockerfile声明(以及其他声明)如下:
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)
pwd
成为 /root
(即 $HOME
为 root
)之后,但它仍然在 /tmp
.我在这里犯了一个明显的错误吗?有没有更好的恢复方法pwd
到它的“原始”值。
似乎最好的方法是明确设置您自己的默认值,这样您就可以确保它是一致的,例如:
ENV HOME /root
WORKDIR $HOME
.. do something in /root ..
WORKDIR /tmp
.. do something else in /tmp ..
WORKDIR $HOME
.. continue back in /root ..
The WORKDIR instruction can resolve environment variables previously set using ENV. You can only use environment variables explicitly set in the Dockerfile.
关于docker - Dockerfile 中的 WORKDIR $HOME 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38423202/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4