Skip to content

Run Locally on Docker

Nadeem Mohammad edited this page Jun 11, 2020 · 1 revision

Create folder and files

Dockerfile

FROM openjdk:8-jdk-alpine

MAINTAINER Mohammad Nadeem

# Refer to Maven build -> finalName
ARG JAR_FILE=wishing-app*.jar

# cd /opt/app
WORKDIR /opt/app

# cp target/spring-boot-web.jar /opt/app/wishing-app.jar
COPY ${JAR_FILE} wishing-app.jar
COPY population_report.xlsx population_report.xlsx
COPY application.properties application.properties

# java -jar /opt/app/wishing-app.jar
ENTRYPOINT ["java","-jar","wishing-app.jar"]

Config and data file

Add application.properties and excel file

Build image

E:\wishing-docker-app>docker build -t wishing-app:latest .
E:\wishing-docker-app>docker images
REPOSITORY              TAG                  IMAGE ID            CREATED             SIZE
wishing-app             latest               b2c53469f187        39 seconds ago      142MB
E:\wishing-docker-app>docker run -dit wishing-app:latest
1e5d92f3d01a3f1ff7841be639fc07641dc1575694afb650a1518be9a297f48f
E:\wishing-docker-app>docker logs 1e5d92f3d01a3f1ff7841be639fc07641dc1575694afb650a1518be9a297f48f

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.0.RELEASE)

2020-06-10 17:03:14.918  INFO 1 --- [           main] c.g.mnadeem.wishing.WishingApplication   : Starting WishingApplication v2.0.0 with PID 1 (/opt/app/wishing-app.jar started by root in /opt/app)
2020-06-10 17:03:14.925 DEBUG 1 --- [           main] c.g.mnadeem.wishing.WishingApplication   : Running with Spring Boot v2.3.0.RELEASE, Spring v5.2.6.RELEASE
2020-06-10 17:03:14.926  INFO 1 --- [           main] c.g.mnadeem.wishing.WishingApplication   : No active profile set, falling back to default profiles: default
2020-06-10 17:03:15.460 TRACE 1 --- [           main] c.g.m.w.s.DefaultWishingDataService      : Stop on load error : false

We can even use docker run -dit --restart unless-stopped option to make sure application starts after every boot.