Skip to content

Commit 21b6817

Browse files
committed
deploy: 76bbb5b
1 parent 64fab26 commit 21b6817

File tree

9 files changed

+50
-50
lines changed

9 files changed

+50
-50
lines changed

index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

post/dockerize-spring-boot/index.html

Lines changed: 11 additions & 11 deletions
Large diffs are not rendered by default.

post/index.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts | Norbert Benczúr</title><link>https://nukesz.github.io/post/</link><atom:link href="https://nukesz.github.io/post/index.xml" rel="self" type="application/rss+xml"/><description>Posts</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><copyright>2025</copyright><lastBuildDate>Mon, 10 Feb 2025 20:53:53 +0100</lastBuildDate><image><url>https://nukesz.github.io/img/icon-192.png</url><title>Posts</title><link>https://nukesz.github.io/post/</link></image><item><title>Dockerize a Spring Boot application</title><link>https://nukesz.github.io/post/dockerize-spring-boot/</link><pubDate>Mon, 10 Feb 2025 20:53:53 +0100</pubDate><guid>https://nukesz.github.io/post/dockerize-spring-boot/</guid><description>&lt;h2 id="introduction">Introduction&lt;/h2>
2-
&lt;p>In this post, I&amp;rsquo;d like to present a few options to ship a spring boot application in a docker container. There are many easy ways to &lt;em>dockerize a spring boot&lt;/em> (probably a nice google hit search), but I don&amp;rsquo;t see too much discussion around the pros and cons. So let&amp;rsquo;s jump into it&lt;/p>
2+
&lt;p>In this post, I&amp;rsquo;d like to present a few options to ship a spring boot application in a docker container. There are many ways to &lt;em>dockerize a spring boot&lt;/em> (probably a nice google hit search), but I don&amp;rsquo;t see too much discussion around the pros and cons. So let&amp;rsquo;s jump into it.&lt;/p>
33
&lt;h2 id="create-new-project">Create new project&lt;/h2>
4-
&lt;p>Just go to &lt;a href="https://start.spring.io/">https://start.spring.io/&lt;/a> and create a new project. I&amp;rsquo;ll be using:&lt;/p>
4+
&lt;p>Go to &lt;a href="https://start.spring.io/">https://start.spring.io/&lt;/a> and create a new project. I&amp;rsquo;ll be using:&lt;/p>
55
&lt;ul>
66
&lt;li>Gradle - Groovy&lt;/li>
77
&lt;li>Spring Boot 3.4.2&lt;/li>
88
&lt;li>Java 21&lt;/li>
99
&lt;li>Dependencies: Spring Web&lt;/li>
1010
&lt;/ul>
11-
&lt;p>For demonstration, I&amp;rsquo;m going to add the &amp;ldquo;/ping&amp;rdquo; endpoint and it&amp;rsquo;s going to return &amp;ldquo;pong&amp;rdquo;. Just simply create &lt;code>PingController.java&lt;/code>.&lt;/p>
11+
&lt;p>For demonstration, I&amp;rsquo;m going to add a &amp;ldquo;/ping&amp;rdquo; endpoint and it&amp;rsquo;s going to return &amp;ldquo;pong&amp;rdquo;. Just simply create &lt;code>PingController.java&lt;/code>.&lt;/p>
1212
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-java" data-lang="java">&lt;span style="color:#f92672">package&lt;/span> com.nukesz.demo&lt;span style="color:#f92672">;&lt;/span>
1313
&lt;span style="color:#f92672">import&lt;/span> org.springframework.web.bind.annotation.GetMapping&lt;span style="color:#f92672">;&lt;/span>
1414
&lt;span style="color:#f92672">import&lt;/span> org.springframework.web.bind.annotation.RestController&lt;span style="color:#f92672">;&lt;/span>
@@ -28,7 +28,7 @@ java -jar build/libs/dockerize-spring-boot-0.0.1-SNAPSHOT.jar
2828
&lt;p>The jar is actually created with the &lt;code>bootJar&lt;/code> task. You can learn more about it in the &lt;a href="https://docs.spring.io/spring-boot/docs/2.5.1/gradle-plugin/reference/htmlsingle/#packaging-executable.and-plain-archives">spring doc&lt;/a>&lt;/p>
2929
&lt;/blockquote>
3030
&lt;p>Verify our REST API is working as expected:&lt;/p>
31-
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-sh" data-lang="sh">curl http://localhost:8080/ping
31+
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-sh" data-lang="sh">$ curl http://localhost:8080/ping
3232
&amp;gt; Pong!
3333
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="create-dockerfile-manually">Create &lt;code>Dockerfile&lt;/code> manually&lt;/h2>
3434
&lt;p>Our application is ready, so let&amp;rsquo;s create a docker image for it. First let&amp;rsquo;s&lt;/p>
@@ -39,21 +39,21 @@ COPY build/libs/dockerize-spring-boot-*.jar /opt/app/myapp.jar
3939
CMD &lt;span style="color:#f92672">[&lt;/span>&lt;span style="color:#e6db74">&amp;#34;java&amp;#34;&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;-jar&amp;#34;&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;/opt/app/myapp.jar&amp;#34;&lt;/span>&lt;span style="color:#f92672">]&lt;/span>
4040
&lt;/code>&lt;/pre>&lt;/div>&lt;p>You can build and run the Docker image:&lt;/p>
4141
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-sh" data-lang="sh">docker build -t dockerize-spring-boot .
42-
docker run -it -p 8080:8080 --rm $ dockerize-spring-boot
42+
docker run -it -p 8080:8080 --rm dockerize-spring-boot
4343
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Verify that we can reach our REST API within the container as expected:&lt;/p>
4444
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-sh" data-lang="sh">$ curl http://localhost:8080/ping
4545
&amp;gt; Pong!
4646
&lt;/code>&lt;/pre>&lt;/div>&lt;p>Are we done? - Not at all.&lt;/p>
4747
&lt;h3 id="whats-the-problem">What&amp;rsquo;s the problem?&lt;/h3>
4848
&lt;p>Creating &lt;code>Dockerfile&lt;/code> manually has its pros and cons. It&amp;rsquo;s the most flexible solution where you control everything. No dependency needed.&lt;/p>
49-
&lt;p>The problem comes when you need more than a &lt;code>Hello World&lt;/code> example.&lt;/p>
49+
&lt;p>But I think the biggest drawback with this approach is that &lt;strong>it seems&lt;/strong> everything is working, but in fact it is hiding the underlining work that is missing. The problem comes when you need more than a &lt;code>Hello World&lt;/code> example.&lt;/p>
5050
&lt;h4 id="repetitive">Repetitive&lt;/h4>
5151
&lt;p>When you have more than 1 java app to dockerize, the number of dockerfiles starts to grow and you have to maintain and update each file independently.&lt;/p>
5252
&lt;h4 id="efficiency">Efficiency&lt;/h4>
5353
&lt;p>In this simple example, we defined our base image and started our &lt;em>fat jar&lt;/em>. But is that the most optimal way to build and run a spring boot (or any other java) application?
54-
For example let&amp;rsquo;s change a single file in our application and build the image again:&lt;/p>
54+
For example, let&amp;rsquo;s change a single file in our application and build the image again:&lt;/p>
5555
&lt;div class="highlight">&lt;pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-sh" data-lang="sh">&lt;span style="color:#75715e"># Let&amp;#39;s measure the re-build&lt;/span>
56-
$ time &lt;span style="color:#f92672">(&lt;/span> ./gradlew build -x test; docker build -t dockerize-spring-boot .&lt;span style="color:#f92672">)&lt;/span>
56+
$ time &lt;span style="color:#f92672">(&lt;/span> ./gradlew build -x test; docker build -t dockerize-spring-boot . &lt;span style="color:#f92672">)&lt;/span>
5757
&amp;gt; ..
5858
&amp;gt; &lt;span style="color:#f92672">=&lt;/span>&amp;gt; &lt;span style="color:#f92672">[&lt;/span>3/3&lt;span style="color:#f92672">]&lt;/span> COPY build/libs/dockerize-spring-boot-*.jar /opt/app/myapp.jar
5959
&amp;gt; ..

tags/docker/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html><html lang=en-us><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><meta http-equiv=x-ua-compatible content="IE=edge"><meta name=generator content="Source Themes Academic 4.4.0"><meta name=author content="Norbert Benczúr"><meta name=description content="Norbert Benczúr's blog"><link rel=alternate hreflang=en-us href=https://nukesz.github.io/tags/docker/><meta name=theme-color content="#2962ff"><link rel=stylesheet href=https://cdnjs.cloudflare.com/ajax/libs/academicons/1.8.6/css/academicons.min.css integrity="sha256-uFVgMKfistnJAfoCUQigIl+JfUaP47GrRKjf6CTPVmw=" crossorigin=anonymous><link rel=stylesheet href=https://use.fontawesome.com/releases/v5.6.0/css/all.css integrity=sha384-aOkxzJ5uQz7WBObEZcHvV5JvRW3TUc2rNPA7pe3AwnsUohiw1Vj2Rgx2KSOkF5+h crossorigin=anonymous><link rel=stylesheet href=https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.css integrity="sha256-ygkqlh3CYSUri3LhQxzdcm0n1EQvH2Y+U5S2idbLtxs=" crossorigin=anonymous><link rel=stylesheet href=https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/github.min.css crossorigin=anonymous title=hl-light><link rel=stylesheet href=https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/dracula.min.css crossorigin=anonymous title=hl-dark disabled><link rel=stylesheet href="https://fonts.googleapis.com/css?family=Montserrat:400,700|Roboto:400,400italic,700|Roboto+Mono&display=swap"><link rel=stylesheet href=/css/academic.min.04a87a1cb9027e3c50f566322527c56f.css><script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;ga('create','UA-127428919-1','auto');ga('require','eventTracker');ga('require','outboundLinkTracker');ga('require','urlChangeTracker');ga('send','pageview');</script><script async src=https://www.google-analytics.com/analytics.js></script><script async src=https://cdnjs.cloudflare.com/ajax/libs/autotrack/2.4.1/autotrack.js integrity="sha512-HUmooslVKj4m6OBu0OgzjXXr+QuFYy/k7eLI5jdeEy/F4RSgMn6XRWRGkFi5IFaFgy7uFTkegp3Z0XnJf3Jq+g==" crossorigin=anonymous></script><link rel=alternate href=/tags/docker/index.xml type=application/rss+xml title="Norbert Benczúr"><link rel=manifest href=/index.webmanifest><link rel=icon type=image/png href=/img/icon-32.png><link rel=apple-touch-icon type=image/png href=/img/icon-192.png><link rel=canonical href=https://nukesz.github.io/tags/docker/><meta property="twitter:card" content="summary"><meta property="twitter:site" content="@NorbertBenczur"><meta property="twitter:creator" content="@NorbertBenczur"><meta property="og:site_name" content="Norbert Benczúr"><meta property="og:url" content="https://nukesz.github.io/tags/docker/"><meta property="og:title" content="docker | Norbert Benczúr"><meta property="og:description" content="Norbert Benczúr's blog"><meta property="og:image" content="https://nukesz.github.io/img/icon-192.png"><meta property="twitter:image" content="https://nukesz.github.io/img/icon-192.png"><meta property="og:locale" content="en-us"><meta property="og:updated_time" content="2025-02-10T20:53:53+01:00"><title>docker | Norbert Benczúr</title></head><body id=top data-spy=scroll data-offset=70 data-target=#TableOfContents><aside class=search-results id=search><div class=container><section class=search-header><div class="row no-gutters justify-content-between mb-3"><div class=col-6><h1>Search</h1></div><div class="col-6 col-search-close"><a class=js-search href=#><i class="fas fa-times-circle text-muted" aria-hidden=true></i></a></div></div><div id=search-box><input name=q id=search-query placeholder=Search... autocapitalize=off autocomplete=off autocorrect=off spellcheck=false type=search></div></section><section class=section-search-results><div id=search-hits></div></section></div></aside><nav class="navbar navbar-light fixed-top navbar-expand-lg py-0 compensate-for-scrollbar" id=navbar-main><div class=container><a class=navbar-brand href=/>Norbert Benczúr</a>
22
<button type=button class=navbar-toggler data-toggle=collapse data-target=#navbar aria-controls=navbar aria-expanded=false aria-label="Toggle navigation">
3-
<span><i class="fas fa-bars"></i></span></button><div class="collapse navbar-collapse" id=navbar><ul class="navbar-nav mr-auto"><li class=nav-item><a class=nav-link href=/#about><span>Home</span></a></li><li class=nav-item><a class=nav-link href=/#posts><span>Posts</span></a></li></ul><ul class="navbar-nav ml-auto"><li class=nav-item><a class="nav-link js-search" href=#><i class="fas fa-search" aria-hidden=true></i></a></li><li class=nav-item><a class="nav-link js-dark-toggle" href=#><i class="fas fa-moon" aria-hidden=true></i></a></li></ul></div></div></nav><div class="universal-wrapper pt-3"><h1>docker</h1></div><div class=universal-wrapper><div><h2><a href=/post/dockerize-spring-boot/>Dockerize a Spring Boot application</a></h2><div class=article-style>Introduction In this post, I&rsquo;d like to present a few options to ship a spring boot application in a docker container. There are many easy ways to dockerize a spring boot (probably a nice google hit search), but I don&rsquo;t see too much discussion around the pros and cons. So let&rsquo;s jump into it
4-
Create new project Just go to https://start.spring.io/ and create a new project. I&rsquo;ll be using:
3+
<span><i class="fas fa-bars"></i></span></button><div class="collapse navbar-collapse" id=navbar><ul class="navbar-nav mr-auto"><li class=nav-item><a class=nav-link href=/#about><span>Home</span></a></li><li class=nav-item><a class=nav-link href=/#posts><span>Posts</span></a></li></ul><ul class="navbar-nav ml-auto"><li class=nav-item><a class="nav-link js-search" href=#><i class="fas fa-search" aria-hidden=true></i></a></li><li class=nav-item><a class="nav-link js-dark-toggle" href=#><i class="fas fa-moon" aria-hidden=true></i></a></li></ul></div></div></nav><div class="universal-wrapper pt-3"><h1>docker</h1></div><div class=universal-wrapper><div><h2><a href=/post/dockerize-spring-boot/>Dockerize a Spring Boot application</a></h2><div class=article-style>Introduction In this post, I&rsquo;d like to present a few options to ship a spring boot application in a docker container. There are many ways to dockerize a spring boot (probably a nice google hit search), but I don&rsquo;t see too much discussion around the pros and cons. So let&rsquo;s jump into it.
4+
Create new project Go to https://start.spring.io/ and create a new project. I&rsquo;ll be using:
55
Gradle - Groovy Spring Boot 3.</div></div></div><script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin=anonymous></script><script src=https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/4.1.4/imagesloaded.pkgd.min.js integrity="sha256-lqvxZrPLtfffUl2G/e7szqSvPBILGbwmsGE1MKlOi0Q=" crossorigin=anonymous></script><script src=https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.6/isotope.pkgd.min.js integrity="sha256-CBrpuqrMhXwcLLUd5tvQ4euBHCdh7wGlDfNz8vbu/iI=" crossorigin=anonymous></script><script src=https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.js integrity="sha256-X5PoE3KU5l+JcX+w09p/wHl9AzK333C4hJ2I9S5mD4M=" crossorigin=anonymous></script><script src=https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js integrity="sha256-aYTdUrn6Ow1DDgh5JTc3aDGnnju48y/1c8s1dgkYPQ8=" crossorigin=anonymous></script><script src=https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/languages/r.min.js></script><script>hljs.initHighlightingOnLoad();</script><script>const search_index_filename="/index.json";const i18n={'placeholder':"Search...",'results':"results found",'no_results':"No results found"};const content_type={'post':"Posts",'project':"Projects",'publication':"Publications",'talk':"Talks"};</script><script id=search-hit-fuse-template type=text/x-template>
66
<div class="search-hit" id="summary-{{key}}">
77
<div class="search-hit-content">

0 commit comments

Comments
 (0)