quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.68k stars 2.65k forks source link

Dockerfile.multistage not working (looks like an image issue) #10132

Closed fabstao closed 4 years ago

fabstao commented 4 years ago

Describe the bug Can't build docker native image with the application, can't even copy pom.xml to the build image (quay.io/quarkus/centos-quarkus-maven:19.3.1-java11) it looks like an issue with the image because I can copy files into my own Docker images, even based on CentOS.

Expected behavior Build application into docker container image

Actual behavior Docker build fails in first stage

To Reproduce Steps to reproduce the behavior:

  1. Use a working Quarkus application on a docker enabled host
  2. Move to the project directory (where pom.xml is located)
  3. copy src/main/docker/Dockerfile.multistage .
  4. docker build -t .
  5. Copy error message appears
$ docker build -t quay.io/fabstao/rokostacio2 .
Sending build context to Docker daemon  3.584kB
Step 1/20 : FROM quay.io/quarkus/centos-quarkus-maven:19.3.1-java11 AS build
19.3.1-java11: Pulling from quarkus/centos-quarkus-maven
524b0c1e57f8: Pull complete 
1beb771cdd17: Pull complete 
Digest: sha256:f83fc08a9b5594df9681a60c156d41e0b225eece3889f4eb299b01684ab5696c
Status: Downloaded newer image for quay.io/quarkus/centos-quarkus-maven:19.3.1-java11
 ---> 0b3da81f4a33
Step 2/20 : COPY pom.xml /project/pom.xml
COPY failed: stat /var/lib/docker/tmp/docker-builder136156981/pom.xml: no such file or directory
$ 

Configuration

## Stage 1 : build with maven builder image with native capabilities
FROM quay.io/quarkus/centos-quarkus-maven:19.3.1-java11 AS build
COPY pom.xml /usr/src/app/
RUN mvn -f /usr/src/app/pom.xml -B de.qaware.maven:go-offline-maven-plugin:1.2.5:resolve-dependencies
COPY src /usr/src/app/src
USER root
RUN chown -R quarkus /usr/src/app
USER quarkus
RUN mvn -f /usr/src/app/pom.xml -Pnative clean package

## Stage 2 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal
WORKDIR /work/
COPY --from=build /usr/src/app/target/*-runner /work/application

# set up permissions for user `1001`
RUN chmod 775 /work /work/application \
  && chown -R 1001 /work \
  && chmod -R "g+rwX" /work \
  && chown -R 1001:root /work

EXPOSE 8080
USER 1001

CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
$ docker build -t quay.io/fabstao/rokostacio2 .
Sending build context to Docker daemon  3.584kB
Step 1/15 : FROM quay.io/quarkus/centos-quarkus-maven:19.3.1-java11 AS build
 ---> 0b3da81f4a33
Step 2/15 : COPY pom.xml /usr/src/app/
COPY failed: stat /var/lib/docker/tmp/docker-builder336411649/pom.xml: no such file or directory

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

Environment (please complete the following information):

Additional context

$ docker version
Client:
 Version:           18.09.1
 API version:       1.39
 Go version:        go1.11.6
 Git commit:        4c52b90
 Built:             Tue, 03 Sep 2019 19:59:35 +0200
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.09.1
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.11.6
  Git commit:       4c52b90
  Built:            Tue Sep  3 17:59:35 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Please help

ejba commented 4 years ago

Hi @fabstao,

I should have a look at the .dockerignore file. The file has the following content by default.

*
!target/*-runner
!target/*-runner.jar
!target/lib/* 

As you can see, all files are ignored (i.e. pom file) except the artifacts. Hence, you have to adjust the rules according to your needs (e.g. add !pom.xml).

fabstao commented 4 years ago

Oh got it, now it's working, thanks a lot!