Docker COPY仅复制一个子目录,而不复制整个构建上下文

时间:2019-08-19 14:03:02

标签: maven docker build copy quarkus

我用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

这里可能是什么错误?

1 个答案:

答案 0 :(得分:1)

Quarkus Maven原型添加了一个.dockerignore文件。其中仅target文件夹未从Docker中排除。因此,仅复制了target文件夹。

相关问题