{"id":602,"date":"2017-11-03T09:00:42","date_gmt":"2017-11-03T03:30:42","guid":{"rendered":"http:\/\/www.cyberaka.com\/?p=602"},"modified":"2017-11-03T09:01:30","modified_gmt":"2017-11-03T03:31:30","slug":"adding-docker-support-in-spring-boot-application","status":"publish","type":"post","link":"https:\/\/www.cyberaka.com\/?p=602","title":{"rendered":"Adding docker support in Spring Boot application"},"content":{"rendered":"<p>Adding docker containerization support in a working Spring Boot application is surprisingly easy.<\/p>\n<p>Step 1: Add the docker maven plugin to your pom file.<\/p>\n<pre>&lt;build&gt;\r\n    &lt;plugins&gt;\r\n        &lt;plugin&gt;\r\n            &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;spring-boot-maven-plugin&lt;\/artifactId&gt;\r\n        &lt;\/plugin&gt;\r\n        &lt;plugin&gt;\r\n            &lt;groupId&gt;com.spotify&lt;\/groupId&gt;\r\n            &lt;artifactId&gt;dockerfile-maven-plugin&lt;\/artifactId&gt;\r\n            &lt;version&gt;1.3.4&lt;\/version&gt;\r\n            &lt;configuration&gt;\r\n                &lt;repository&gt;${project.artifactId}&lt;\/repository&gt;\r\n            &lt;\/configuration&gt;\r\n        &lt;\/plugin&gt;\r\n    &lt;\/plugins&gt;\r\n&lt;\/build&gt;<\/pre>\n<p>Step 2: Build the application as well as the docker image<\/p>\n<pre>mvn clean package install dockerfile:build<\/pre>\n<p>Step 3: I have a local docker registry setup in my Lan so I prefer to push this image to my network registry manually (this can be automated as well however).<\/p>\n<pre class=\"p1\"><span class=\"s1\">docker tag my-app:latest my_network_registry_host:5000\/my-app<\/span><\/pre>\n<p>Step 4: Now we can bootup this docker image anywhere in the network.<\/p>\n<pre>docker run \\\r\n--detach \\\r\n--link &lt;any database link&gt; \\\r\n-e &lt;Environment variable 1&gt; \\\r\n-e &lt;Environment variable 2&gt; \\\r\n-p 8080:8080 \\\r\n--name my-app \\\r\nmy_network_registry_host:5000\/simply-hr\r\n<\/pre>\n<div>\u00a0Step 5: Checkout the application URL @ http:\/\/localhost:8080. Tail the log if you want to<\/div>\n<pre>docker logs --follow simply-hr<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Adding docker containerization support in a working Spring Boot application is surprisingly easy. Step 1: Add the docker maven plugin to your pom file. &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt; &lt;artifactId&gt;spring-boot-maven-plugin&lt;\/artifactId&gt; &lt;\/plugin&gt; &lt;plugin&gt; &lt;groupId&gt;com.spotify&lt;\/groupId&gt; &lt;artifactId&gt;dockerfile-maven-plugin&lt;\/artifactId&gt; &lt;version&gt;1.3.4&lt;\/version&gt; &lt;configuration&gt; &lt;repository&gt;${project.artifactId}&lt;\/repository&gt; &lt;\/configuration&gt; &lt;\/plugin&gt; &lt;\/plugins&gt; &lt;\/build&gt; Step 2: Build the application as well as the docker image mvn clean package install [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57,28],"tags":[],"class_list":["post-602","post","type-post","status-publish","format-standard","hentry","category-docker","category-miscellaneous"],"_links":{"self":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=602"}],"version-history":[{"count":2,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/602\/revisions"}],"predecessor-version":[{"id":604,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=\/wp\/v2\/posts\/602\/revisions\/604"}],"wp:attachment":[{"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyberaka.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}