{"id":354,"date":"2022-02-26T22:05:33","date_gmt":"2022-02-26T22:05:33","guid":{"rendered":"https:\/\/liangqi.org\/?p=354"},"modified":"2022-02-26T22:05:34","modified_gmt":"2022-02-26T22:05:34","slug":"how-to-generate-docker-image","status":"publish","type":"post","link":"https:\/\/liangqi.org\/?p=354","title":{"rendered":"How to generate docker image"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"fabric8-maven-plugin\">Fabric8 maven plugin<\/h2>\n\n\n\n<p>The first way to do is using fabric8 maven plugin (<a href=\"https:\/\/dmp.fabric8.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/dmp.fabric8.io\/<\/a>) . We have something like this to define the image in pom.xml:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        &lt;profile>\n            &lt;id>docker-image&lt;\/id>\n            &lt;build>\n                &lt;plugins>\n                    &lt;plugin>\n                        &lt;groupId>io.fabric8&lt;\/groupId>\n                        &lt;artifactId>docker-maven-plugin&lt;\/artifactId>\n                        &lt;configuration>\n                            &lt;images>\n                                &lt;image>\n                                    &lt;name>z\/daco&lt;\/name>\n                                    &lt;build>\n                                        &lt;cleanup>none&lt;\/cleanup>\n                                        &lt;from>XXX\/centos7-openjdk8:5&lt;\/from>\n                                        &lt;maintainer>XX&lt;\/maintainer>\n                                        &lt;tags>\n                                            &lt;tag>latest&lt;\/tag>\n                                            &lt;tag>${project.version}&lt;\/tag>\n                                            &lt;tag>${project.version}-${git.commit.id.abbrev}&lt;\/tag>\n                                        &lt;\/tags>\n                                        &lt;runCmds>\n                                            &lt;run>curl -v -u deployer:Jf8f907Q https:\/\/nexus.XX.io\/nexus\/service\/local\/repositories\/security\/content\/kafka\/client\/certs\/kafka.client.truststore.jks -o \/maven\/kafka.client.truststore.jks&lt;\/run>\n                                        &lt;\/runCmds>\n                                        &lt;assembly>\n                                            &lt;descriptor>${basedir}\/src\/main\/docker\/fabric8\/assembly.xml&lt;\/descriptor>\n                                        &lt;\/assembly>\n                                        &lt;ports>\n                                            &lt;port>${dataconnect.port.service}&lt;\/port>\n                                            &lt;port>${dataconnect.port.admin}&lt;\/port>\n                                        &lt;\/ports>\n                                        &lt;cmd>\n                                            &lt;shell>java $JAVA_OPTS -jar \/maven\/${project.artifactId}-${project.version}-shaded.jar $DROPWIZARD_COMMAND \/maven\/XX-application.yml&lt;\/shell>\n                                        &lt;\/cmd>\n                                    &lt;\/build>\n                                &lt;\/image>\n                            &lt;\/images>\n                        &lt;\/configuration>\n                        &lt;executions>\n                            &lt;execution>\n                                &lt;id>build-docker-image&lt;\/id>\n                                &lt;phase>package&lt;\/phase>\n                                &lt;goals>\n                                    &lt;goal>build&lt;\/goal>\n                                &lt;\/goals>\n                            &lt;\/execution>\n                        &lt;\/executions>\n                    &lt;\/plugin>\n                &lt;\/plugins>\n            &lt;\/build>\n        &lt;\/profile><\/code><\/pre>\n\n\n\n<p>And assembly file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;assembly xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n          xmlns=\"http:\/\/maven.apache.org\/plugins\/maven-assembly-plugin\/assembly\/1.1.2\"\n          xsi:schemaLocation=\"http:\/\/maven.apache.org\/plugins\/maven-assembly-plugin\/assembly\/1.1.2 http:\/\/maven.apache.org\/xsd\/assembly-1.1.2.xsd\">\n    &lt;id>${project.artifactId}&lt;\/id>\n    &lt;files>\n        &lt;file>\n            &lt;source>target\/${project.artifactId}-${project.version}-shaded.jar&lt;\/source>\n            &lt;outputDirectory>\/&lt;\/outputDirectory>\n        &lt;\/file>\n        &lt;file>\n            &lt;source>XX-application.yml&lt;\/source>\n            &lt;outputDirectory>\/&lt;\/outputDirectory>\n        &lt;\/file>\n        &lt;file>\n            &lt;source>src\/main\/resources\/liquibase\/db.changelog-0.0.1.xml&lt;\/source>\n            &lt;outputDirectory>\/liquibase&lt;\/outputDirectory>\n        &lt;\/file>\n        &lt;file>\n            &lt;source>src\/main\/resources\/liquibase\/migrations.xml&lt;\/source>\n            &lt;outputDirectory>\/liquibase&lt;\/outputDirectory>\n        &lt;\/file>\n    &lt;\/files>\n    &lt;fileSets>\n        &lt;fileSet>\n            &lt;directory>src\/main\/resources\/dedicatedresources&lt;\/directory>\n            &lt;outputDirectory>\/dedicatedresources&lt;\/outputDirectory>\n        &lt;\/fileSet>\n    &lt;\/fileSets>\n&lt;\/assembly>\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"framework-build-in-target\">Framework build-in target<\/h2>\n\n\n\n<p>If you are using Sprint boot, it has the maven docker image target <code>mvn spring-boot:build-image<\/code>. Based on the doc <a href=\"https:\/\/spring.io\/blog\/2020\/01\/27\/creating-docker-images-with-spring-boot-2-3-0-m1\">here<\/a> it has some benefit like using exploded folder other than fat jar; but I guess it may not flexible enough.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"write-your-own-dockerfile\"> Write your own dockerfile<\/h2>\n\n\n\n<p>This is more direct and I guess it has most flexibility. Here is one example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM openjdk:8-jdk-alpine\nEXPOSE 8080\nARG JAR_FILE=target\/my-application.jar\nADD ${JAR_FILE} app.jar\nENTRYPOINT &#91;\"java\",\"-jar\",\"\/app.jar\"]<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fabric8 maven plugin The first way to do is using fabric8 maven plugin (https:\/\/dmp.fabric8.io\/) . We have something like this to define the image in pom.xml: And assembly file: Framework build-in target If you are using Sprint boot, it has the maven docker image target mvn spring-boot:build-image. Based on the doc here it has some benefit like using exploded folder other than fat jar; but I guess it may not flexible enough. Write your own dockerfile This is more direct and I guess it has most flexibility. Here is one example:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,16],"tags":[],"class_list":["post-354","post","type-post","status-publish","format-standard","hentry","category-docker","category-16"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to generate docker image - Liangqi\u2018s Technical Journey<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/liangqi.org\/?p=354\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to generate docker image - Liangqi\u2018s Technical Journey\" \/>\n<meta property=\"og:description\" content=\"Fabric8 maven plugin The first way to do is using fabric8 maven plugin (https:\/\/dmp.fabric8.io\/) . We have something like this to define the image in pom.xml: And assembly file: Framework build-in target If you are using Sprint boot, it has the maven docker image target mvn spring-boot:build-image. Based on the doc here it has some benefit like using exploded folder other than fat jar; but I guess it may not flexible enough. Write your own dockerfile This is more direct and I guess it has most flexibility. Here is one example:\" \/>\n<meta property=\"og:url\" content=\"https:\/\/liangqi.org\/?p=354\" \/>\n<meta property=\"og:site_name\" content=\"Liangqi\u2018s Technical Journey\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-26T22:05:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-26T22:05:34+00:00\" \/>\n<meta name=\"author\" content=\"liangqi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"liangqi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/liangqi.org\/?p=354#article\",\"isPartOf\":{\"@id\":\"https:\/\/liangqi.org\/?p=354\"},\"author\":{\"name\":\"liangqi\",\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"headline\":\"How to generate docker image\",\"datePublished\":\"2022-02-26T22:05:33+00:00\",\"dateModified\":\"2022-02-26T22:05:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/liangqi.org\/?p=354\"},\"wordCount\":97,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"articleSection\":[\"Docker\",\"\u6280\u672f\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/liangqi.org\/?p=354#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/liangqi.org\/?p=354\",\"url\":\"https:\/\/liangqi.org\/?p=354\",\"name\":\"How to generate docker image - Liangqi\u2018s Technical Journey\",\"isPartOf\":{\"@id\":\"https:\/\/liangqi.org\/#website\"},\"datePublished\":\"2022-02-26T22:05:33+00:00\",\"dateModified\":\"2022-02-26T22:05:34+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/liangqi.org\/?p=354#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/liangqi.org\/?p=354\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/liangqi.org\/?p=354#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/liangqi.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to generate docker image\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/liangqi.org\/#website\",\"url\":\"https:\/\/liangqi.org\/\",\"name\":\"Liangqi\u2018s Technical Journey\",\"description\":\"Chasing Excellence; Enjoy life.\",\"publisher\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/liangqi.org\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\",\"name\":\"liangqi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg\",\"contentUrl\":\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg\",\"width\":2560,\"height\":1920,\"caption\":\"liangqi\"},\"logo\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/liangqi.org\"],\"url\":\"https:\/\/liangqi.org\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to generate docker image - Liangqi\u2018s Technical Journey","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/liangqi.org\/?p=354","og_locale":"en_US","og_type":"article","og_title":"How to generate docker image - Liangqi\u2018s Technical Journey","og_description":"Fabric8 maven plugin The first way to do is using fabric8 maven plugin (https:\/\/dmp.fabric8.io\/) . We have something like this to define the image in pom.xml: And assembly file: Framework build-in target If you are using Sprint boot, it has the maven docker image target mvn spring-boot:build-image. Based on the doc here it has some benefit like using exploded folder other than fat jar; but I guess it may not flexible enough. Write your own dockerfile This is more direct and I guess it has most flexibility. Here is one example:","og_url":"https:\/\/liangqi.org\/?p=354","og_site_name":"Liangqi\u2018s Technical Journey","article_published_time":"2022-02-26T22:05:33+00:00","article_modified_time":"2022-02-26T22:05:34+00:00","author":"liangqi","twitter_card":"summary_large_image","twitter_misc":{"Written by":"liangqi","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/liangqi.org\/?p=354#article","isPartOf":{"@id":"https:\/\/liangqi.org\/?p=354"},"author":{"name":"liangqi","@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"headline":"How to generate docker image","datePublished":"2022-02-26T22:05:33+00:00","dateModified":"2022-02-26T22:05:34+00:00","mainEntityOfPage":{"@id":"https:\/\/liangqi.org\/?p=354"},"wordCount":97,"commentCount":0,"publisher":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"articleSection":["Docker","\u6280\u672f"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/liangqi.org\/?p=354#respond"]}]},{"@type":"WebPage","@id":"https:\/\/liangqi.org\/?p=354","url":"https:\/\/liangqi.org\/?p=354","name":"How to generate docker image - Liangqi\u2018s Technical Journey","isPartOf":{"@id":"https:\/\/liangqi.org\/#website"},"datePublished":"2022-02-26T22:05:33+00:00","dateModified":"2022-02-26T22:05:34+00:00","breadcrumb":{"@id":"https:\/\/liangqi.org\/?p=354#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/liangqi.org\/?p=354"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/liangqi.org\/?p=354#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/liangqi.org\/"},{"@type":"ListItem","position":2,"name":"How to generate docker image"}]},{"@type":"WebSite","@id":"https:\/\/liangqi.org\/#website","url":"https:\/\/liangqi.org\/","name":"Liangqi\u2018s Technical Journey","description":"Chasing Excellence; Enjoy life.","publisher":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/liangqi.org\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3","name":"liangqi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/liangqi.org\/#\/schema\/person\/image\/","url":"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg","contentUrl":"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg","width":2560,"height":1920,"caption":"liangqi"},"logo":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/liangqi.org"],"url":"https:\/\/liangqi.org\/?author=1"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/354","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=354"}],"version-history":[{"count":1,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/354\/revisions"}],"predecessor-version":[{"id":355,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/354\/revisions\/355"}],"wp:attachment":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}