简体   繁体   中英

Why is my java docker image created successfully on laptop but when uploading to google cloud run it fails?

dockerfile:

FROM maven as builder
# Set the working directory.
WORKDIR /usr/src/mymaven
COPY ./ /usr/src/mymaven
CMD [ "maven:3.3-jdk-8" , "mvn" , "clean" , "install" ]

FROM openjdk:8
COPY --from=builder /usr/src/mymaven/target /usr/src/myapp
WORKDIR /usr/src/myapp
CMD ["java", "-jar" , "Build-Backend-0.0.1-SNAPSHOT.jar"]

In local build is successful using the command:

docker build -t javaservice .

But when trying to upload image to google cloud run using command:

gcloud builds submit --tag gcr.io/$(gcloud config get-value project)/javaservice

It gives error:

Step 6/8 : COPY --from=builder /usr/src/mymaven/target /usr/src/myapp
COPY failed: stat /var/lib/docker/overlay2/201005fffe25fce26b6ef6067586ae02dd20a0ad7d63b846d5ee6260d833d52d/merged/usr/src/mymaven/target: no such file or directory
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1

What might be wrong here?

Couldn't find an answer so posting the solution that I found on my own.
If you can build docker images on local machine but google cloud run is failing for whatever reason, you can push the locally made image directly to google container registry.

gcloud auth configure-docker #integrate gcloud to docker
docker build . --tag gcr.io/[PROJECT-ID]/[IMAGENAME]
docker push gcr.io/[PROJECT-ID]/[IMAGENAME]

Source: https://cloud.google.com/run/docs/building/containers

It appears that the target directory in your local directory is being ignored, either by .gitignore or .gcloudignore , and thus isn't being sent to Cloud Build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM