├── Dockerfile ├── README.md ├── pom.xml └── src ├── main └── java │ └── com │ └── javatechie │ └── spring │ └── boot │ └── docker │ └── demo │ └── SpringBootDockerApplication.java └── test └── java └── com └── javatechie └── spring └── boot └── docker └── demo └── SpringBootDockerApplicationTests.java /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8 2 | EXPOSE 8080 3 | ADD target/spring-boot-docker.jar spring-boot-docker.jar 4 | ENTRYPOINT ["java","-jar","/spring-boot-docker.jar"] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-dockerize 2 | How to Dockerize Spring Boot Application 3 | 4 | # Build Docker Image 5 | $ docker build -t spring-boot-docker.jar . 6 | 7 | # Check Docker Image 8 | $ docker image ls 9 | 10 | # Run Docker Image 11 | $ docker run -p 9090:8080 spring-boot-docker.jar 12 | 13 | In the run command, we have specified that the port 8080 on the container should be mapped to the port 9090 on the Host OS. 14 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.2.RELEASE 9 | 10 | 11 | com.javatechie 12 | spring-boot-docker 13 | 0.0.1-SNAPSHOT 14 | spring-boot-docker 15 | Dockerize spring boot applicatio n 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-test 30 | test 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-maven-plugin 39 | 40 | 41 | spring-boot-docker 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/main/java/com/javatechie/spring/boot/docker/demo/SpringBootDockerApplication.java: -------------------------------------------------------------------------------- 1 | package com.javatechie.spring.boot.docker.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @SpringBootApplication 9 | @RestController 10 | public class SpringBootDockerApplication { 11 | 12 | @GetMapping("/message") 13 | public String getMessage() { 14 | return "Welcome to JavaTechie..!!"; 15 | } 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(SpringBootDockerApplication.class, args); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/javatechie/spring/boot/docker/demo/SpringBootDockerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.javatechie.spring.boot.docker.demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringBootDockerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | --------------------------------------------------------------------------------