How to Run a Jar in a Docker Container
Apr 19, 2021
Create the Dockerfile
# Start with a base image containing Java runtime
FROM java:8-jdk-alpine
COPY /spring-boot-0.0.1-SNAPSHOT.jar /opt/
WORKDIR /opt/
EXPOSE 9090
ENTRYPOINT [“java”, “-jar”, “spring-boot-0.0.1-SNAPSHOT.jar”]
- jar file spring-boot-0.0.1-SNAPSHOT.jar is in the same directory where Dockerfile is
docker build -t <give a name for docker container here > .
ex : docker build -t spring-boot .
docker run -p 9090:9090 <docker image name>
ex: docker run -p 9090:9090 spring-boot