14. Docker – Implementation => Project Three (MySql)
Docker – Implementation => Project Three (MySql)
This project can be download from this
github URL.
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-mysql
Created two controller – 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_3).
Go to application properties file.and
give a server port.
# ----------- SQL - DATA BASE CONFIGURATIONS -----------------
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#3306 - local mysql server |
3300 - container mysql server - mysql_server
spring.datasource.url=jdbc:mysql://localhost:3306/dockerSpringbootMySql
#spring.datasource.url=jdbc:mysql://mysql_server:3300/dockerSpringbootMySql
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect
=org.hibernate.dialect.MySQL5Dialect
server.port=8083
Create Docker file name Dockerfile and
add below configuration.
FROM openjdk:11
ARG JAR_FILE=target/docker_SB_3.jar
COPY ${JAR_FILE} app.jar
EXPOSE 8083
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_3.
Then run the project and see the
output.
Then go to the project folder. Inside docker-springBoot-mysql
you can see Dockerfile also. Right click in the docker-springBoot-mysql folder
and open in terminal.
docker build -f Dockerfile -t sb_prj_three_img .
docker images
docker run -p 8083:8083 --name sb_prj_three_cont -d
sb_prj_three_img
OR
docker run -p 7083:8083 --name sb_prj_three_cont -d
sb_prj_three_img
docker container ls
Comments
Post a Comment