Docker COPY 只复制一个子目录,而不是整个构建上下文
Docker COPY only copies one sub-directory, not whole build context
我在 Java 中使用 Quarkus' Maven 原型创建了一个虚拟项目。我想将整个构建上下文复制到我的 Docker 容器中。
当我在当前目录中执行 ls -al
时,我得到了这个结果:
drwxr-xr-x 12 my.user staff 384 19 Aug 15:57 .
drwxr-xr-x 12 my.user staff 384 19 Aug 15:39 ..
-rw-r--r-- 1 my.user staff 53 19 Aug 15:39 .dockerignore
-rw-r--r-- 1 my.user staff 295 19 Aug 15:39 .gitignore
drwxr-xr-x 7 my.user staff 224 19 Aug 15:45 .idea
drwxr-xr-x 3 my.user staff 96 19 Aug 15:39 .mvn
-rw-r--r-- 1 my.user staff 78 19 Aug 15:57 Dockerfile
-rwxrwxr-x 1 my.user staff 10078 19 Aug 15:39 mvnw
-rw-rw-r-- 1 my.user staff 6609 19 Aug 15:39 mvnw.cmd
-rw-r--r-- 1 my.user staff 3691 19 Aug 15:39 pom.xml
drwxr-xr-x 4 my.user staff 128 19 Aug 15:39 src
drwxr-xr-x 15 my.user staff 480 19 Aug 15:40 target
这是我的 Dockerfile
:
FROM maven:3-jdk-11-slim
WORKDIR /home/mvn
COPY ./ .
RUN ls -al
RUN mvn verify
很遗憾,只有目标文件夹被复制。这是 docker build .
:
的结果输出
Sending build context to Docker daemon 8.425MB
Step 1/5 : FROM maven:3-jdk-11-slim
---> b67032e30f89
Step 2/5 : WORKDIR /home/mvn
---> Running in 90dc6171c4be
Removing intermediate container 90dc6171c4be
---> 3cf149c09c43
Step 3/5 : COPY ./ .
---> bf0869cf8577
Step 4/5 : RUN ls -al
---> Running in 733891348a3c
total 12
drwxr-xr-x 1 root root 4096 Aug 19 14:00 .
drwxr-xr-x 1 root root 4096 Aug 19 14:00 ..
drwxr-xr-x 3 root root 4096 Aug 19 14:00 target
Removing intermediate container 733891348a3c
---> f425feab5580
Step 5/5 : RUN mvn verify
---> Running in 29e2dae052f6
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.078 s
[INFO] Finished at: 2019-08-19T14:00:51Z
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/home/mvn). Please verify you invoked Maven from the correct directory. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
The command '/bin/sh -c mvn verify' returned a non-zero code: 1
这里可能是什么错误?
Quarkus Maven 原型添加了一个 .dockerignore
文件。其中只有 target
文件夹未从 Docker 中排除。因此只复制了 target
文件夹。
我在 Java 中使用 Quarkus' Maven 原型创建了一个虚拟项目。我想将整个构建上下文复制到我的 Docker 容器中。
当我在当前目录中执行 ls -al
时,我得到了这个结果:
drwxr-xr-x 12 my.user staff 384 19 Aug 15:57 .
drwxr-xr-x 12 my.user staff 384 19 Aug 15:39 ..
-rw-r--r-- 1 my.user staff 53 19 Aug 15:39 .dockerignore
-rw-r--r-- 1 my.user staff 295 19 Aug 15:39 .gitignore
drwxr-xr-x 7 my.user staff 224 19 Aug 15:45 .idea
drwxr-xr-x 3 my.user staff 96 19 Aug 15:39 .mvn
-rw-r--r-- 1 my.user staff 78 19 Aug 15:57 Dockerfile
-rwxrwxr-x 1 my.user staff 10078 19 Aug 15:39 mvnw
-rw-rw-r-- 1 my.user staff 6609 19 Aug 15:39 mvnw.cmd
-rw-r--r-- 1 my.user staff 3691 19 Aug 15:39 pom.xml
drwxr-xr-x 4 my.user staff 128 19 Aug 15:39 src
drwxr-xr-x 15 my.user staff 480 19 Aug 15:40 target
这是我的 Dockerfile
:
FROM maven:3-jdk-11-slim
WORKDIR /home/mvn
COPY ./ .
RUN ls -al
RUN mvn verify
很遗憾,只有目标文件夹被复制。这是 docker build .
:
Sending build context to Docker daemon 8.425MB
Step 1/5 : FROM maven:3-jdk-11-slim
---> b67032e30f89
Step 2/5 : WORKDIR /home/mvn
---> Running in 90dc6171c4be
Removing intermediate container 90dc6171c4be
---> 3cf149c09c43
Step 3/5 : COPY ./ .
---> bf0869cf8577
Step 4/5 : RUN ls -al
---> Running in 733891348a3c
total 12
drwxr-xr-x 1 root root 4096 Aug 19 14:00 .
drwxr-xr-x 1 root root 4096 Aug 19 14:00 ..
drwxr-xr-x 3 root root 4096 Aug 19 14:00 target
Removing intermediate container 733891348a3c
---> f425feab5580
Step 5/5 : RUN mvn verify
---> Running in 29e2dae052f6
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.078 s
[INFO] Finished at: 2019-08-19T14:00:51Z
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/home/mvn). Please verify you invoked Maven from the correct directory. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
The command '/bin/sh -c mvn verify' returned a non-zero code: 1
这里可能是什么错误?
Quarkus Maven 原型添加了一个 .dockerignore
文件。其中只有 target
文件夹未从 Docker 中排除。因此只复制了 target
文件夹。