To dockerize an App , we'd need to create a Dockerfile.
Follow below steps to create a Dockerfile for Dockerizing a Springboot App -
Create a file named - Dockerfile and copy below content
note : f is always small in Dockerfile
FROM openjdk:8-jdk-alpine
RUN mkdir -p /tmp
WORKDIR /tmp
ADD /target/sample-app.jar sample-app.jar
ENTRYPOINT ["java", "-jar" , "/tmp/sample-app.jar" ]
If you have jar pushed to a remote artifactory you can download it using wget.
Use below Dockerfile for remote repo
Use below Dockerfile for remote repo
FROM openjdk:8-jdk-alpine
RUN mkdir -p /tmp
WORKDIR /tmp
wget <url of repo>/sample-app.jar
wget <url of repo>/sample-app.jar
ENTRYPOINT ["java", "-jar" , "/tmp/sample-app.jar" ]
Build the docker image
docker build -t sample-docker-build:0.1 .
To Run the Docker image
docker run -p 9001:8080sample-docker-build:0.1
- 8080 is the default port on which springboot app runs
- 9001 is the port exposed for it, so if a user has to access the app it would be 9001.
- You can expose the same port at which the app is running