Docker build using Spring Boot, Maven, and Cloud 9

0

Hello,

I am trying to get up and running with Spring Boot, Maven, and AWS. I am following this tutorial.

I had to install a different version of maven, as when I ran sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt under Install Apache Maven the console said it wasn't able to unzip apache-maven-3.8.1-bin.tar.gz. I had to download a different version, apache-maven-3.9.6-bin.tar.gz and I was able to unzip this.

I also had to change M2_HOME to M3_HOME under Set up Apache Maven, and I had to unset M2_HOME. Then I was able to proceed.

In Cloud 9, the return of mvn --version is

Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T17:29:23+00:00)
Maven home: /usr/share/apache-maven
Java version: 17.0.9, vendor: Amazon.com Inc.
Java home: /usr/lib/jvm/java-17-amazon-corretto.x86_64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "6.1.66-91.160.amzn2023.x86_64", arch: "amd64", family: "unix"

I am at the part Build and tag the Petclinic docker image. When I execute the command docker build -t petclinic . the console returns

 => [internal] load build definition from Dockerfile 
...
 => ERROR [2/4] ADD target/spring-petclinic-2.3.0.jar app.jar                                                                                                                                                                                  0.0s
------
 > [2/4] ADD target/spring-petclinic-2.3.0.jar app.jar:
------
Dockerfile:3
--------------------
   1 |     FROM public.ecr.aws/bitnami/java:latest
   2 |     VOLUME /tmp
   3 | >>> ADD target/spring-petclinic-2.3.0.jar app.jar
   4 |     EXPOSE 80
   5 |     RUN apt-get update
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 3f20ae07-a774-435d-86a5-f05e04520cc5::ljcblcc6ijbrhcn5q5fi0vwyr: "/target/spring-petclinic-2.3.0.jar": not found

I am trying to fix the error caused by ADD target/spring-petclinic-2.3.0.jar app.jar .

My Dockerfile is

FROM public.ecr.aws/bitnami/java:latest
VOLUME /tmp
ADD target/spring-petclinic-2.3.0.jar app.jar
EXPOSE 80
RUN apt-get update
RUN apt-get -y install awscli
ENTRYPOINT env spring.datasource.password=$(aws ssm get-parameter --name /database/password --with-decrypt --region $AWS_REGION | grep Value | cut -d '"' -f4) java -Djava.security.egd=file:/dev/./urandom -jar /app.jar

I found this post which talks about commands relative to your Dockerfile. I tried to update the command in my Dockerfile to

ADD /home/ec2-user/environment/aws-apprunner-terraform/petclinic/target/spring-petclinic-2.3.0.jar app.jar

but this returned a similar error to the one above. The return of pwd is

/home/ec2-user/environment/aws-apprunner-terraform/petclinic

and then the return of ls is

Dockerfile docker-compose.yml pom.xml readme.md src.

I noticed that target directory is not there. Should it?

Thank you for the help in getting started with Spring!

Jeff F
gefragt vor 4 Monaten262 Aufrufe
2 Antworten
1
Akzeptierte Antwort

Hello,

From query I can clearly see that “/target/spring-petclinic-2.3.0.jar": not found .

As you already mentioned that target folder was not there and as per Dockerfile command “ADD target/spring-petclinic-2.3.0.jar app.jar” it will search for spring-petclinic-2.3.0.jar in "target" folder in current directory .

As per shared document The compiled java classes were placed in spring-petclinic/target/classes, which is another standard convention employed by Maven.

Hence I will suggest you to please verify and see why target folder is not getting generated . If you need further assistance we need to dig deeper into logs. And I will request you to please reach out to us by opening a support case with us.

I will be more than happy to assist with that.

Thank you!!!

AWS
SUPPORT-TECHNIKER
beantwortet vor 4 Monaten
profile picture
EXPERTE
überprüft vor einem Monat
0

Hi Jeff, before running the Docker Build command, did you run the Package the application using Apache Maven?

cd ~/environment/aws-apprunner-terraform/petclinic
mvn package -Dmaven.test.skip=true

This will create the target folder and the "spring-petclinic-2.3.0.jar" that you are missing into your Docker Build process

AWS
beantwortet vor 4 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen