13. Docker – Implementation => Project Two (H2)

Docker – Implementation => Project Two (H2)



This project can be download from this github URL.

https://github.com/LahiruPriyankara/DockerTestProjects


This is very basic spring boot project work with H2 in memory database to test docker containerization.

Open Spring tool suit.

Create new Spring boot Proj name docker-springBoot-h2

Created two controllers – download and follow the codes for that.

Go to pom.xml and give a custom name to the jar file which will be generated (docker_SB_2).

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>docker_SB_2</finalName>
</build>

Go to application properties file.and give a server port.

server.port=8082

 

spring.mvc.view.prefix= /view/

spring.mvc.view.suffix=.jsp

 

# ----------- SQL - INMEMORY DATA BASE CONFIGURATIONS | H2  -----------------

spring.h2.console.enabled=true

spring.datasource.platform=h2

spring.datasource.url=jdbc:h2:mem:dockerSpringBH2_1

 

 

Create Docker file name Dockerfile and add below configuration.

FROM openjdk:11

ARG JAR_FILE=target/docker_SB_2.jar

COPY ${JAR_FILE} app.jar

EXPOSE 8082

ENTRYPOINT ["java","-jar","/app.jar"]

 

Right click on the project => run as => maven install.

Then jar file is generated in the target folder with named docker_SB_2.

Then run the project and see the output.

Then go to the project folder. Inside docker-springBoot-h2 you can see Dockerfile also. Right click in the docker-springBoot-h2 folder and open in terminal.

docker build -f Dockerfile  -t sb_prj_two_img  .

docker images

docker run -p 8082:8082 --name sb_prj_two_cont -d sb_prj_two_img

                                                                OR

docker run -p 7082:8082 --name sb_prj_two_cont -d sb_prj_two_img

 

docker container ls

Comments

Popular posts from this blog

02. Spring – Creating spring project clone it with GIT step by step.

02.What is MicroService?

06.Mongo DB - Query part 2 (Aggregation)