不能在Dockerfile中设置shellvariables
我想写一个Dockerfile来设置我的GOPATHvariables,但是当我去使用这个variables的时候它是空的,例如:
Step 7 : RUN export GOPATH=/root/go ---> Running in 5691396dd55b ---> 17d76f7de05f Removing intermediate container 5691396dd55b Step 8 : RUN echo $GOPATH ---> Running in b2cd6ef885d0 ---> 54b5a3d5c697
我试图做一个dockerbuild设 – 无caching。 但是我得到了同样的结果; 有任何想法吗?
您应该使用ENV
在Dockerfile中设置环境variables。
请参阅https://docs.docker.com/reference/builder/#env
来自文档的其他说明:
注意:环境持久性可能会导致意外的影响。 例如,设置
ENV DEBIAN_FRONTEND noninteractive
可能会将apt-get
用户混淆在基于Debian的映像上。 要为单个命令设置一个值,请使用RUN <key>=<value> <command>
。
“”部分非常重要,因为没有它,环境variables只能在发生RUN的那一层设置,所以对后续层没有影响。 ENV
将坚持子图层。