Tuesday, June 26, 2018

Dockerizing Spring Boot App using Maven

This post details the steps required to dockerize an existing Spring Boot App
  1. Create a Spring Boot App
  2. Run  and verify the working of the App
  3. Include the following  build plugin details  in  POM file to create the docker image
    <plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <configuration>
       <imageName>hellodocker</imageName>
       <baseImage>java:8</baseImage>
    <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
         <resources>
    <resource>
               <targetPath>/</targetPath>
       <directory>${project.build.directory}</directory>
       <include>${project.build.finalName}.jar</include>
    </resource>
    </resources>
     </configuration>
    </plugin>
  4. To create the docker image ,use the maven build and in the configuration specify docker:build
  5. The required files are downloaded and then docker file and image  are created in /target/docker
  6. From the docker console chech if the image is created using the command docker images
  7. Start the container using the image  on Port 9090 with the  following command
    • docker run -it -p 9090:8080 <>
    • Verify the working of using the URL http://localhost:9090/hello
  8. Start another container on port 9091
    • docker run -it -p 9091:8080 <>
    • Verify the working of 2nd Container using the URL http://localhost:9091/hello

No comments:

Post a Comment