爲什麼maven3 docker鏡像中的/root/.m2文件寫入的內容在構建過程中是持久的?無法在docker maven container中寫入〜/ .m2
一個簡單dockerfile:
FROM maven:3-jdk-8
RUN touch /root/.m2/testfilehere && ls -a /root/.m2
RUN ls -a /root/.m2
CMD ["bash"]
產生以下輸出。
$ docker build -t test --no-cache .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM maven:3-jdk-8
---> 42e3884987fb
Step 2 : RUN touch /root/.m2/testfilehere && ls -a /root/.m2
---> Running in 1c1dc5e9f082
.
..
testfilehere
---> 3da352119c4d
Removing intermediate container 1c1dc5e9f082
Step 3 : RUN ls -a /root/.m2
---> Running in df506db8c1dd
.
..
---> d07cc155b20e
Removing intermediate container df506db8c1dd
Step 4 : RUN stat /root/.m2/testfilehere
---> Running in af44f30aafe5
stat: cannot stat ‘/root/.m2/testfilehere’: No such file or directory
The command '/bin/sh -c stat /root/.m2/testfilehere' returned a non-zero code: 1
當中間容器存在時,在第一個命令中創建的文件不見了。
此外,這不會發生在Ubuntu的圖像,只是maven。
編輯:使用ADD hostfile /root/.m2/containerfile
確實是一種解決方法,但不是我想要的。
入口點不應該是一個問題。在運行容器之前,即在執行文件創建的Dockerfile命令之後進行擦除。 – npit
正如此鏈接https://docs.docker中的解釋。com/engine/reference/builder /#/ understand-how-cmd-and-entrypoint-interact 在運行CMD/bin/bash之前執行入口點 如果你想確定當你做出ls seconde時間,你可以看到copy_reference_file.log settings-docker.xml 它們從maven ref目錄複製而來 – Thibaut