Home > Back-end >  Getting failed to solve with frontend dockerfile.v0: failed to read dockerfile
Getting failed to solve with frontend dockerfile.v0: failed to read dockerfile

Time:12-22

I keep getting failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount235234165/Dockerfile: no such file or directory error when trying to build a docker image of image my spring boot project. I am new to docker and don't really know what I am doing so any help is appreciated. I am following along with this article https://www.javaguides.net/2022/12/deploy-spring-boot-mysql-application-to-docker.html?m=1

docker build -t demo .
PS C:\Users\shawn\demo> docker build -t demo .
[ ] Building 0.1s (1/2)
 => [internal] load build definition from Dockerfile                                                                                                                               0.0s
 => => transferring dockerfile: 2B                                                                                                                                                 0.0s 
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount235234165/Dockerfile: no such file or directory

Here is my Docker file

FROM openjdk:11

LABEL mentainer="shawn"

WORKDIR /app

COPY target/demo-0.0.1-SNAPSHOT.jar /app/demo.jar

ENTRYPOINT ["java", "-jar", "demo.jar"]

I've tried building a docker image a different way but still received the same error.

FROM openjdk:11
COPY target/demo-0.0.1-SNAPSHOT.jar /app/demo.jar
ENTRYPOINT ["java", "-jar", "demo.jar"]

I've also tried running the command from the root directory of the project and had gotten this error.

C:\Users\shawn\demo\src\main\java\passion\project\demo>docker build -t demo .
[ ] Building 2.6s (8/8) FINISHED
 => [internal] load build definition from Dockerfile                                                               0.3s
 => => transferring dockerfile: 193B                                                                               0.2s
 => [internal] load .dockerignore                                                                                  0.1s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for docker.io/library/openjdk:11                                                      1.6s
 => [auth] library/openjdk:pull token for registry-1.docker.io                                                     0.0s
 => CANCELED [1/3] FROM docker.io/library/openjdk:11@sha256:99bac5bf83633e3c7399aed725c8415e7b569b54e03e4599e580f  0.3s
 => => resolve docker.io/library/openjdk:11@sha256:99bac5bf83633e3c7399aed725c8415e7b569b54e03e4599e580fc9cdb7c21  0.2s
 => => sha256:99bac5bf83633e3c7399aed725c8415e7b569b54e03e4599e580fc9cdb7c21ab 1.04kB / 1.04kB                     0.0s
 => [internal] load build context                                                                                  0.2s
 => => transferring context: 2B                                                                                    0.0s
 => CACHED [2/3] WORKDIR /app                                                                                      0.0s
 => ERROR [3/3] COPY target/demo-0.0.1-SNAPSHOT.jar /app/demo.jar                                                  0.0s
------
 > [3/3] COPY target/demo-0.0.1-SNAPSHOT.jar /app/demo.jar:

CodePudding user response:

First of all you have to run the build command within the directory containing the Dockerfile (or replacing the . by pointing to the Dockerfile), which is apparently within your source directory according to your last snippet.

That's not a good approach as your Dockerfile is inside the package structure of your sources. Thus, you cannot access target/demo-0.0.1-SNAPSHOT.jar as relative path during build.

Suggestion: move Dockerfile to C:\Users\shawn\demo which is the root of you project. And verify that your java project is generated in C:\Users\shawn\demo\targetso target/demo-0.0.1-SNAPSHOT.jar exists.

  • Related