【问题标题】:Docker COPY only copies one sub-directory, not whole build contextDocker COPY 只复制一个子目录,而不是整个构建上下文
【发布时间】:2019-08-19 14:03:02
【问题描述】:

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

这可能是什么错误?

【问题讨论】:

  • 我猜有东西被添加到你的.dockerignore
  • @atline 谢谢,这就是解决方案!
  • 您想发布您的解决方案@HaroldL.Brown,让未来的用户了解需要解决的问题吗?

标签: maven docker build copy quarkus


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    相关资源
    最近更新 更多