12. Docker – Implementation => Project one


Docker – Implementation => Project one


This project can be download from this github URL.

 https://github.com/LahiruPriyankara/DockerTestProjects


This is very basic spring boot project to test docker containerization.

Open Spring tool suit.

Create new Spring boot Proj name docker-springBoot-one

Create a controller class under src directory.

package com.lahiru.demo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Controller {
@GetMapping("/test")
public String testMethod() {
return "Called successfully..!";
}

}

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

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

..

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

server.port=8081

 

Create Docker file name Dockerfile and add below configuration.

FROM openjdk:11

ARG JAR_FILE=target/docker_SB_1.jar

COPY ${JAR_FILE} app.jar

EXPOSE 9091

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_1.

Then run the project and see the output.

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

docker build -f Dockerfile  -t sb_prj_one_img  .

docker images

docker run -p 8081:8081 --name sb_prj_one_cont -d sb_prj_one_img

                                                            OR

docker run -p 7081:8081 --name sb_prj_one_cont -d sb_prj_one_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)