简体   繁体   中英

How to build docker image which combines angular and spring boot app?

I have two different projects spring boot and angular project. Now I want to build docker image which will include both the projects. I checked maven-resource-plugin which copies angular files to spring-boot /target/classes/resources directory . And docker-maven-plugin which builds docker image from spring-boot-app .

Should I use output of both plugins to create desired output or should I change the way I create docker image? Now my docker image is builds image from spring boot app.

FROM java:8
VOLUME /tmp
ADD gs-spring-boot-docker-0.1.0.jar app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

You can host wwwroot generated by webpack as static files served by your spring boot application.

Instead running your angular app on webpack-dev by executing ng serve you should geneate static files by ng build --prod (I may misspell some commands, writing from memory) and place them as static files in spring boot app, like shown here https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot

I'm not a spring expert, but you can do this like you said. Of course, having a separate container with only frontend would be nice, but if your spring app will be closly tied up with frontend and will not serve api for other services, you can go with solution hosting angular on spring boot server.

In the end, you are just sending html, js and css files to client's browser where the code is acutally executed, so hosting static files will not be a burden.

Having api separated from frontend content serving service (ie nginx, httpd) would be reasonable if you would like to scale only the backend service for handling larger traffic, but I think it's not the case here.

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