How to load the web app folder to docker container - spring-boot

I am new to the docker technology. I have a spring boot application running on my local machine. I need to move the target jar file to the docker container.
This spring boot application is contains rest services and some controller will display the view (JSP) with the help of dispatcher servlet.
While creating the container, I am getting 404 Error for the views returned from the dispatcher servlet. What is the command I need to place in my dockerfile to move my static web app folder to the container ?.
Thanks in advance.
Container is working fine for the rest services. Rest services to perform CRUD with mysql server.
My Dockerfile :
FROM openjdk:8
EXPOSE 7070
ADD target/docker_app.jar docker_app.jar
ENTRYPOINT ["java","-jar","docker_app.jar"]

You should not wrap the the web application as jar.
add the following tag in your pom xml
<packaging>war</packaging>
change the Dockerfile command to deploy war file instead of jar.
Dockerfile :
FROM openjdk:8
EXPOSE 7070
ADD target/docker_app.war docker_app.war
ENTRYPOINT ["java","-jar","docker_app.war"]

Related

Start spring boot jar file as part of tomcat start

There is a way I can start the spring boot jar file as part of tomcat start(catalina.bat start).
I have a spring cloud api gateway which does not support war file deployment.
In a bare metal box, I have installed the tomcat, and as part of deployment I have converted all microservice into war file and able to deploy it into tomcat/webapp folder and up and running.
As spring cloud api gateway does not support war file, I kept this application with embed tomcat.
Now I need this jar file as well get started along with the tomcat [catalina.bat start].
In tomcat I have seen there is something shared.loader option in catalina.properties file.
I have kept the jar file in below path as shown below and when I try to start it, jar file is not getting picked up.
Need to know if there is a way to start the spring boot application [jar file] as part of tomcat [catalina.bat start] start.

How do I override configuration in application.yml in spring boot (2.4.2) generated docker image?

I used spring boot 2.4.2
Generated docker image using the command mvn spring-boot:build-image -Dspring-boot.build-image.imageName=XXXXXX.azurecr.io/fake-XXXXX:0215
I have hostnames in application.yml that I need to override
So I passed -Dspring.data.mongodb.host=mongo_db in docker-compose under command: BUT it is not overriding. .. Below screenshot for reference.
I understand that Buildpacks are used to build the layered jar.
If this was docker image created by me manually and not by spring boot then I would have ENTRYPOINT in Dockerfile and command in docker-compose where I would have given command: Dspring.data.mongodb.host=mongo_db -jar fake-XXXX.jar
I know #6 works but would like to use the latest and greatest spring boot in my new project. Hence kindly let me know your thoughts.
Why don't you try the approach via Spring Config or Harshi Corp Consul KV feature and read your config from there. Check-in your config to a repo and have config framework read it from there and pass it to your app? You can change the config at runtime (probably requires restart of containers to reload the modified KV fields in some case)

How to I externalize my configuration for my spring-boot war application?

I have a spring-boot war application that is packaged using Maven, and I need to deploy it as docker image. Now I am done with creating docker image, my current problem is how do I pass external configuration? I am not running my spring-boot application as java -jar myapp.war. The person responsible for deploying this image will need to pass the path of the configuration file to docker image.

Docker | How to build and deploy war file in jboss container hosted in Docker

I have a jboss image hosted in Docker, along with several others. I am able to run the jboss image and use it as container to deploy webapps.
Currently using IntelliJ to configure a Docker configuration and deploy war files directly from IntelliJ and pointing to the docker configuration within IntelliJ.
I am looking for ways by which I can deploy this war file directly in my jboss image at Docker.
Basically looking at ways to deploy war file without any IntelliJ intervention, with the use of docker-compose to build jboss image along with added war targets successfully deployed.
What sort of changes need to be done in jboss.yml file and Dockerfile for jboss image?
If you want the .war file to be integral part of your image, then you just need to add it as a file resource to your jboss deployment dir during your image assembly via dockerfile. Say your docker file goes like this:
FROM jboss/wildfly
COPY myapp.war /opt/jboss/wildfly/standalone/deployments/
Of course you need to adjust the paths to match your setup and distribution, you can for example use maven docker plugin.
Other option is just to build your server without any deployments and use jboss cli or web admin interface to deploy it. Again you can automate it via maven or RUN command in dockerfile.

Spring Maven rest web service - What is the URL when deploying on real web server?

I followed this tutorial https://spring.io/guides/gs/rest-service/ by creating maven project in intellij, addind pom.xml etc. Then I run on localhost exactly as written in the tutorial and all works:
http://localhost:8080/greeting
When greeting came from the annotation of method in the controller #RequestMapping("/greeting").
Then I made JAR artifact & deployed it to Tomact on 'real server' (Elastic beanstalk environment running EC2 instance on AWS).
I got from AWS the base URL of my webserver running Tomact. What is now the suffix to my service? This is NOT working:
http://someEnvironmentName.elasticbeanstalk.com/greeting
EDIT: How I made the artifact JAR
In intellij I can compile & run maven project and then test it in localhost. So what I did:
Right click on the project name->Open Module Settings->Artifacts->Add->Jar
Build->Build Artifacts->Selecting the Jar from above
Maybe I need to build WAR? And how to deal with the POM.xml? Now my pom is exactly as in the linked tutorial.
Thanks,
If you use spring-boot, you donĀ“t need a tomcat because spring include an embedded tomcat. Only you run the application with Maven. So, the advantage of spring-boot is not dependent on an application server and using other containers such as Docker.
Do you put the port in the call to your webserver?
On the other hand, check your server logs to see if there are any problem.
Solution (Thanks to #JBNizet suggestion):
Follow this link http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
Modify the Application.java file
Modify the pom.xml (By adding one more dependency)
Then if you are using Intellij IDE under Build->Build Artifacts will be automatically option for WAR file.
Just deploy to AWS elasticbeanstalk instance running EC2 in the usual way. The URL is:
http://someEnvironmentName.elasticbeanstalk.com/greeting

Resources