dockerdirectoryechopwd

Docker COPY no such file or directory


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

Building from openjdk:8-jdk-alpine

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

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"]

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")
}

I am running

docker build .

docker gradle task

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

Solution

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

    The Dockerfile sets:

    ARG DEPENDENCY=target/dependency
    

    And then attempts a COPY operation:

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

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

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

    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:

    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).