We have
seen more definition about the containerization and its time for us to see some
original work in action.
We will See
in this post how to create a docker image and run from it. Of course, it is available
in the spring site as a tutorial. I am providing here my version of achieving it.
1. If your application is maven based
you have to execute the goal as” mvn:package”.
2. Once you execute the package command
it tries to create the jar and run the unit test cases, if you want not to
execute the test cases then you can pass the following along with the goal. -Dmaven.test.skip=true
3. Once the jar is generated you can check
your application is running by calling the jar file. Java -jar springbootdemo-0.0.1-SNAPSHOT.jar
once you execute this, you can see the application started running.
4. Download the docker from the
website. https://docs.docker.com/installation/#installation
and install it in the local. Makesure you are able to run the docker commands
after installation.
1. Create a file named “Dockerfile” with the following contents.
FROM
openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
2 You can run the “docker build -t
employeeservice . “ to create the tag.
you can run the application using the following command.
docker run -p 7010:7010 employeeservice
That’s all Congrats on your first docker app.
No comments:
Write comments