Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Create docker image #25

Closed
mgh87 opened this issue Aug 8, 2018 · 5 comments
Closed

Create docker image #25

mgh87 opened this issue Aug 8, 2018 · 5 comments

Comments

@mgh87
Copy link

mgh87 commented Aug 8, 2018

Hey jonas,

Would you be interested in a pullrequest that enhanced your build with the possibility to build a docker image to deploy your application and showcase this deployment strategy?

Kind regards

@jonashackt
Copy link
Owner

Hi @mgh87 , you mean the Heroku deployment process? So using a Docker image and the Heroku Docker Registry to deploy the app, inkl. TravisCI integration?!? Why not 😃 - would be great to see it. Cheers

@mgh87
Copy link
Author

mgh87 commented Aug 8, 2018

Just thought at first about the approach from https://spring.io/guides/gs/spring-boot-docker/
for creation of the docker image.

But I can also have a look at Heroku+TravisCi.
Its also on my list of technologies to look up.

@Doogiemuc
Copy link

I have setup this. And this was actually pretty easy.

  1. The backend can be packaged with the dockerfile-maven-plugin (created by Spotify!)
  2. The frontend, when built to production is just an HTML and a JS file. You can simply copy this to any webserver, or include it into the backend and let it be served by Springs bundled Jetty.

@jonashackt
Copy link
Owner

Hey @mgh87 - didn't have the time until now, but I provided the project with a full Dockerfile to build & run the complete app. If you need more information, have a look into the docs at: https://github.com/jonashackt/spring-boot-vuejs#build-and-run-with-docker

I didn't want to use the really great dockerfile-maven-plugin as @Doogiemuc mentioned - all because I wanted a more in-depth approach, where there's no so much magic and everyone can have a look into what's going on. The Dockerfile therefore uses Docker multi-stage build, where the second stage is lent from @mgh87 's mentioned guide https://spring.io/guides/gs/spring-boot-docker/:

# Docker multi-stage build

# 1. Building the App with Maven
FROM maven:3-jdk-11

ADD . /springbootvuejs
WORKDIR /springbootvuejs

# Just echo so we can see, if everything is there :)
RUN ls -l

# Run Maven build
RUN mvn clean install


# Just using the build artifact and then removing the build-container
FROM openjdk:11-jdk

MAINTAINER Jonas Hecht

VOLUME /tmp

# Add Spring Boot app.jar to Container
COPY --from=0 "/springbootvuejs/backend/target/backend-0.0.1-SNAPSHOT.jar" app.jar

ENV JAVA_OPTS=""

# Fire up our Spring Boot app by default
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

With that, there are no build artifacts left in the resulting Docker image. Additionally it is also crucial to use a .dockerignore file - otherwise underlying OS specific node modules will be copied into the Docker build container, which could lead to problems (like as with my Mac ✌️ ):

# exclude underlying OS specific node modules
frontend/node*

Just build your own Docker image with docker build . --tag spring-boot-vuejs:latest and run your Docker container with docker run -d -p 8088:8088 --name myspringvuejs spring-boot-vuejs. Then access your app at http://localhost:8088. Have fun!

@mgh87
Copy link
Author

mgh87 commented Jan 29, 2019

That's really nice! Didn't find the time to do it. 😿
Thanks for the work.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants