DEV Community

Discussion on: How to put your Java application into Docker container

wkrzywiec profile image
Wojtek Krzywiec Author

Sure, it is. I don't want to complicate my original blog post and I think introducing a multistage concept right now is not that good (I'll do it in upcoming article) but here is an example of such Dockerfile.

FROM gradle:6.7-jdk8 AS build
RUN mkdir -p /workspace
WORKDIR /workspace
COPY . /workspace
RUN gradle build

FROM java:8-jdk-alpine
COPY --from=build /workspace/build/libs/nasapicture-0.0.1-SNAPSHOT.war /usr/app/
WORKDIR /usr/app
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "nasapicture-0.0.1-SNAPSHOT.war"]
Enter fullscreen mode Exit fullscreen mode

Please let me know if you have any questions

Thread Thread
rasharm_ profile image
Raman Sharma

Awesome. Thanks a lot.

I was just trying to get a containerized Java app running on DigitalOcean App Platform. Here it is:

GitHub logo creativefisher / Nasa-Picture

Single-page application which display NASA's Astronomy Picture of the Day

Deploy to DigitalOcean

This sample demonstrates how to run a Dockerized Java application on DigitalOcean App Platform. Since App Platform doesn't yet support Java, this sample shows how to accomplish this using Dockerfile.

This sample has been adapted from github.com/wkrzywiec/Nasa-Picture

Getting Started

These steps will get this sample application running for you using DigitalOcean.

Note: Following these steps will result in charges for the use of DigitalOcean services

Requirements

Forking the Sample App Source Code

To use all the features of App Platform, you need to be running against your own copy of this application. To make a copy, click the Fork button above and follow the on-screen instructions. In this case, you'll be forking this repo as a starting point for your own app (see Github documentation to learn more about forking repos.

After forking…

Thread Thread
rasharm_ profile image
Raman Sharma

And here is the deployed app: nasa-picture-2-bdhmn.ondigitalocea...

Thread Thread
wkrzywiec profile image
Wojtek Krzywiec Author

Great! 🙂 Again thanks for pointing this out in the post.

And also I'm really impressed that you have adapted this project to deploy it on Digital Ocean