Docker COPY没有这样的文件或目录 [英] Docker COPY no such file or directory

查看:102
本文介绍了Docker COPY没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在复制任务上构建docker映像失败.没有相应的文件和目录.我正在使用hello世界春天的例子

Building docker image fails on copy task. No such file or directory. I am using the hello world example from spring

从openjdk:8-jdk-alpine构建

Building from openjdk:8-jdk-alpine

运行echo $ {PWD} 打印/ Run ls 打印一组普通目录(/usr/var等),但不存在任何项目文件

Run echo ${PWD} prints / Run ls prints a set of normal directories (/usr /var etc) but no project files are present

为什么docker不使用WORKING目录?

Why is docker not using the WORKING directory?

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","hello.Application"]

要复制的文件是通过gradle准备的,我可以确认它们存在:

Files to copy are prepared by gradle and i can confirm that they are present:

task unpack(type: Copy) {
    dependsOn bootJar
    from(zipTree(tasks.bootJar.outputs.files.singleFile))
    into("build/dependency")
}

我在跑步

docker build .

docker gradle任务

docker gradle task

docker {
    name "${project.group}/${bootJar.baseName}"
    copySpec.from(tasks.unpack.outputs).into("dependency")
    buildArgs(['DEPENDENCY': "dependency"])
}

推荐答案

您将收到没有这样的文件或目录"错误,看起来这就是事实.

You're getting a "no such file or directory" error, and it looks like that's the truth.

Dockerfile设置:

The Dockerfile sets:

ARG DEPENDENCY=target/dependency

然后尝试执行 COPY 操作:

COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib

如果您解析 $ {DEPENDENCY} ,则该 COPY 命令如下所示:

If you resolve ${DEPENDENCY}, that COPY command look like:

COPY target/dependency/BOOT-INF/lib /app/lib

存储库中没有 target 目录.也许这是您应该按照本教程创建的内容?从该文档中:

And there is no target directory in the repository. Maybe this is something you're supposed to create by following the tutorial? From that document:

此Dockerfile具有一个DEPENDENCY参数,该参数指向我们解开胖子jar的目录.如果我们做对了,它已经包含一个包含依赖项jar的BOOT-INF/lib目录,以及一个其中包含应用程序类的BOOT-INF/classes目录.请注意,我们正在使用应用程序自己的主类hello.Application(这比使用胖子启动器提供的间接调用要快).

This Dockerfile has a DEPENDENCY parameter pointing to a directory where we have unpacked the fat jar. If we get that right, it already contains a BOOT-INF/lib directory with the dependency jars in it, and a BOOT-INF/classes directory with the application classes in it. Notice that we are using the application’s own main class hello.Application (this is faster than using the indirection provided by the fat jar launcher).

这篇关于Docker COPY没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆