Dockerfile将war复制到本地链接卷(Dockerfile copying war to local linked volume)

我有一个笔记应用程序,我正在maven应用程序中使用Dockerfile构建。 我想将工件note-1.0.war复制到本地链接卷到webapps等文件夹。 到目前为止,我在Dockerfile中有以下内容:

FROM maven:latest MAINTAINER Sonam <emailme@gmail.com> RUN apt-get update WORKDIR /code #Prepare by downloading dependencies ADD pom.xml /code/pom.xml RUN ["mvn", "dependency:resolve"] RUN ["mvn", "verify"] #Adding source, compile and package into a fat jar ADD src /code/src RUN ["mvn", "clean"] #RUN ["mvn", "install"] RUN ["mvn", "install", "-Dmaven.test.skip=true"] RUN mkdir webapps COPY note-1.0.war webapps #COPY code/target/note-1.0.war webapps

不幸的是,我在COPY声明中一直看到“没有这样的文件或目录”。 以下是构建在Docker中的错误:

... ---> bd555aecadbd Removing intermediate container 69c09945f954 Step 11 : RUN mkdir webapps ---> Running in 3d114c40caee ---> 184903fa1041 Removing intermediate container 3d114c40caee Step 12 : COPY note-1.0.war webapps lstat note-1.0.war: no such file or directory

如何将war文件复制到我执行的“webapps”文件夹中

RUN mkdir webapps

谢谢

I have a note app that I am building with a Dockerfile in the maven app. I want to copy the artifact note-1.0.war to local linked volume to folder like webapps. So far I have the following in a Dockerfile:

FROM maven:latest MAINTAINER Sonam <emailme@gmail.com> RUN apt-get update WORKDIR /code #Prepare by downloading dependencies ADD pom.xml /code/pom.xml RUN ["mvn", "dependency:resolve"] RUN ["mvn", "verify"] #Adding source, compile and package into a fat jar ADD src /code/src RUN ["mvn", "clean"] #RUN ["mvn", "install"] RUN ["mvn", "install", "-Dmaven.test.skip=true"] RUN mkdir webapps COPY note-1.0.war webapps #COPY code/target/note-1.0.war webapps

Unfortunately, I keep seeing the "no such file or directory" at the COPY statement. The following is the error from build on Docker hub:

... ---> bd555aecadbd Removing intermediate container 69c09945f954 Step 11 : RUN mkdir webapps ---> Running in 3d114c40caee ---> 184903fa1041 Removing intermediate container 3d114c40caee Step 12 : COPY note-1.0.war webapps lstat note-1.0.war: no such file or directory

How can I copy the war file to a "webapps" folder that I executed in

RUN mkdir webapps

thanks

最满意答案

COPY指令从<src>复制新文件或目录,并将它们添加到路径<dest>的容器的文件系统中。 在您的示例中,docker构建在与Dockerfile相同的目录中查找note-1.0.war 。 如果我理解你的意图,你想要在Dockerfile中从之前的RUN构建的映像中复制一个文件。 所以你应该使用类似的东西

RUN cp /code/target/note-1.0.war /code/webapps

The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>. In your example the docker build is looking for note-1.0.war in the same directory than Dockerfile. If I understand your intention, you want to copy a file inside the image that is build from previous RUN in Dockerfile. So you should use something like

RUN cp /code/target/note-1.0.war /code/webapps

更多推荐