Home > Software engineering >  I can't build a docker image java
I can't build a docker image java

Time:10-08

When trying to assemble an image, I get an error

[ ] Building 0.8s (2/3)
 => [internal] load build definition from Dockerfile                                                               0.0s
[ ] Building 1.0s (2/3)
 => [internal] load build definition from Dockerfile                                                               0.0s
[ ] Building 2.1s (7/7) FINISHED
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 31B                                                                                0.0so
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0so
 => [internal] load metadata for docker.io/library/amazoncorretto:11-alpine-jdk                                    1.9s
 => [auth] library/amazoncorretto:pull token for registry-1.docker.io                                              0.0s
 => [internal] load build context                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
 => CACHED [1/2] FROM docker.io/library/amazoncorretto:11-alpine-jdk@sha256:c9b2999792a19feebe9ccd5e7afd1e1aee857  0.0s
 => ERROR [2/2] COPY target/*.jar app.jar                                                                          0.0s
------
 > [2/2] COPY target/*.jar app.jar:
------
lstat /var/lib/docker/tmp/buildkit-mount4242467964/target: no such file or directory
PS C:\Users\Crank\dev\dock\target> docker build -t dock_image .docker build -t dock_image .

Dockerfile contains

FROM amazoncorretto:11-alpine-jdk
COPY target/*.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

CodePudding user response:

PS C:\Users\Crank\dev\dock\target> docker build -t dock_image .docker build -t dock_image .

You are executing the build from "C:\Users\Crank\dev\dock\target" and then copying files from "target/*.jar":

COPY target/*.jar app.jar

That means you are trying to copy from the directory "C:\Users\Crank\dev\dock\target\target", which doesn't exist according to the build log:

lstat /var/lib/docker/tmp/buildkit-mount4242467964/target: no such file or directory

Just try changing the COPY directive in your Dockerfile:

FROM amazoncorretto:11-alpine-jdk
COPY *.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
  • Related