Azure / acr

Azure Container Registry samples, troubleshooting tips and references
https://aka.ms/acr
Other
162 stars 106 forks source link

COPY command fails during build #693

Closed felipmiguel closed 8 months ago

felipmiguel commented 1 year ago

Describe the bug The command az acr build fails while building an Image that works in my local environment. I applied the workaround described here and it works.

To Reproduce Having a Dockerfile like this:

FROM mcr.microsoft.com/openjdk/jdk:17-mariner as builder
WORKDIR application
ARG ARTIFACT_NAME
COPY ${ARTIFACT_NAME}.jar application.jar
RUN java -Djarmode=layertools -jar application.jar extract

FROM mcr.microsoft.com/openjdk/jdk:17-mariner

WORKDIR application

ARG EXPOSED_PORT
EXPOSE ${EXPOSED_PORT}

ENV SPRING_PROFILES_ACTIVE docker

COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]

Executing:

az acr build -f ../docker/Dockerfile --build-arg ARTIFACT_NAME=target/spring-petclinic-admin-server-3.0.1 .

fails in the last COPY with the following error

Step 14/15 : COPY --from=builder application/application/ ./
failed to export image: failed to create image: failed to get layer sha256:ad931de39c027e3121e73fc649ebf1ee149b3d3dd4f04f48e64978f32e68881b: layer does not exist
2023/05/02 22:54:13 Container failed during run: build. No retries remaining.
failed to run step ID: build: exit status 1

The same Dockerfile built locally with Docker Desktop works fine:

docker build -f ../docker/Dockerfile --build-arg ARTIFACT_NAME=target/spring-petclinic-admin-server-3.0.1

Expected behavior I expect it works at the same level of compatibility than Docker Desktop.

Screenshots If applicable, add screenshots to help explain your problem.

Any relevant environment information

Additional context I applied the workaround described I applied the workaround described here and it works. I modified the original Dockerfile with:

FROM mcr.microsoft.com/openjdk/jdk:17-mariner as builder
WORKDIR application
ARG ARTIFACT_NAME
COPY ${ARTIFACT_NAME}.jar application.jar
RUN java -Djarmode=layertools -jar application.jar extract

FROM mcr.microsoft.com/openjdk/jdk:17-mariner

WORKDIR application

ARG EXPOSED_PORT
EXPOSE ${EXPOSED_PORT}

ENV SPRING_PROFILES_ACTIVE docker

COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
RUN true
COPY --from=builder application/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]

And it works.

If any information is a concern to post here, you can create a support ticket or send an email to acrsup@microsoft.com.

github-actions[bot] commented 9 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] commented 8 months ago

This issue was closed because it has been stalled for 30 days with no activity.