{"id":1241,"date":"2019-04-11T16:08:25","date_gmt":"2019-04-11T14:08:25","guid":{"rendered":"https:\/\/zaven.co\/blog\/?p=1241"},"modified":"2025-04-08T19:55:06","modified_gmt":"2025-04-08T17:55:06","slug":"docker-and-spring-boot-tutorial","status":"publish","type":"post","link":"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/","title":{"rendered":"Docker and Spring Boot tutorial"},"content":{"rendered":"\n<p class=\"lead\"><strong>Do you need to build a simple Spring Boot app with Docker?<\/strong> Keep on reading this <em>Docker and Spring Boot tutorial<\/em> and find out how to configure the Spring Boot development environment using Docker and docker-compose.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-weight: 400;\">Project creation<\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">In the first step, <strong>we will generate a project using the official generator <\/strong><\/span><strong><a href=\"https:\/\/start.spring.io\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">Spring Initializr<\/a><\/strong><span style=\"font-weight: 400;\">. This is a simple-to-use tool that will greatly speed up our work. <\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">We select the fields as follows to generate the project with Kotlin and Spring Boot version 2.0.6. in the field \u201c<\/span>Group\u201d<span style=\"font-weight: 400;\"> from the section \u201c<\/span>Project Metadata\u201d,<span style=\"font-weight: 400;\"> we enter the name of our project package. Usually this is an inverted record of the domain identifying our project. I have entered the domain of my blog there. Below, in the field marked <\/span><b>\u201c<\/b>Artifact\u201d,<span style=\"font-weight: 400;\"> we will enter the name of the artifact. Next, in the section named \u201c<\/span>Dependencies\u201d<span style=\"font-weight: 400;\"> on the right, we find and choose: <\/span><b>JPA, PostgreSQL<\/b><span style=\"font-weight: 400;\">;<\/span> <span style=\"font-weight: 400;\">just as in the picture below.<\/span><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\"   src=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2019\/04\/spring1-730x424.png\" alt=\"Docker and Spring Boot tutorial\" class=\"wp-image-1309\" srcset=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2019\/04\/spring1-730x424.png 730w, https:\/\/zaven.co\/blog\/wp-content\/uploads\/2019\/04\/spring1.png 974w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><figcaption>If you need more information, I recommend that you read <a href=\"https:\/\/docs.spring.io\/initializr\/docs\/current\/reference\/html\/\">Spring Initializr Reference Guide<\/a>.<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-weight: 400;\">Spring Boot Docker \u2013 application configuration<\/span><\/h2>\n\n\n\n<p><strong>We can configure our application with the help of YAML<\/strong><span style=\"font-weight: 400;\"><strong> files<\/strong>. You can find the configuration file in <\/span>resources<span style=\"font-weight: 400;\">. The configuration file is named <\/span>application.properties<span style=\"font-weight: 400;\">. Change its name to <\/span><em>application.yml<\/em><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><i><span style=\"font-weight: 400;\">The relevant path to the configuration file is \/appName\/src\/main\/resources\/application.yml<\/span><\/i><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">The configuration file appears as follows:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">server:\n  port: ${SERVER_PORT}\n\nspring:\n  application:\n    name: ${APPLICATION_NAME}\n  profiles.active: ${ACTIVE_PROFILE}\n  jpa:\n    properties:\n      hibernate:\n        temp:\n          use_jdbc_metadata_defaults: false\n        ddl-auto: update\n        hbm2ddl.auto: create-drop\n        naming-strategy: org.hibernate.cfg.EJB3NamingStrategy\n        show-sql: true\n    database-platform: org.hibernate.dialect.PostgreSQLDialect\n  jackson:\n    property-naming-strategy: CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES\n    serialization:\n      indent_output: true\n  datasource:\n    url: ${DATABASE_URL}\n    username: ${POSTGRES_USER}\n    password: ${POSTGRES_PASSWORD}\n    driver-class-name: org.postgresql.Driver<\/code><\/pre>\n\n\n\n<p>We do not directly provide any values because everything will be injected using the variable environment that we will enter in the file entitled .env.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">APPLICATION_NAME=tasks-rest-api\nACTIVE_PROFILE=development\nSERVER_PORT=3000\nDATABASE_URL=jdbc:postgresql:\/\/localhost:5432\/tasks-rest-api-db\nPOSTGRES_USER=tasks-rest-api-admin\nPOSTGRES_PASSWORD=password\nPOSTGRES_DB=tasks-rest-api-db <\/code><\/pre>\n\n\n\n<p>These variables define the name of the application, the active profile, the port on which our application is available, the connection link to our database located in the docker container as well as the login, password and name of our database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-weight: 400;\">File configuration docker-compose<\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">If you don\u2019t know what docker-compose is, I suggest you read <\/span><a href=\"https:\/\/docs.docker.com\/compose\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\"><span style=\"font-weight: 400;\">documentation<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Only database service can be found in our mini-infrastructure. Nevertheless, nothing prevents the addition of other services e.g. mongodb.<\/span><\/p>\n\n\n\n<p><strong>Now it is necessary to open docker-compose.dev.yml and save it in the main project catalog.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">version: '2'\nservices:\n\n  tasks-rest-api-db:                      \n    image: postgres:10                    \n    container_name: 'tasks-rest-api-db'    \n    ports:\n      - '5432:5432'                        \n    env_file:\n      - .env    <\/code><\/pre>\n\n\n\n<p>Thanks to <strong>docker-compose<\/strong> we are able to clearly define our services, virtual network and provide variable environments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-weight: 400;\">Docker and Spring Boot \u2013 starting the application<\/span><\/h2>\n\n\n\n<p><strong>To run the application, you must indicate the .env file in the application launch settings and launch the database container.<\/strong><span style=\"font-weight: 400;\"><br><\/span><span style=\"font-weight: 400;\">To do this, enable the application startup configuration in the IDE, go to the EnvFile tab and check the Enable EnvFile option and add the file.<\/span><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\"   src=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2019\/04\/spring2-730x460.png\" alt=\"spring boot docker\" class=\"wp-image-1310\" srcset=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2019\/04\/spring2-730x460.png 730w, https:\/\/zaven.co\/blog\/wp-content\/uploads\/2019\/04\/spring2.png 974w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/figure><\/div>\n\n\n\n<p>Now execute the following: <code>docker-compose -f docker-compose.dev.yml<\/code> up in BASH or PowerShell. Then make and run the application (<kbd>shift + F10<\/kbd>).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-weight: 400;\">Summary<\/span><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">In this <em>Docker and Spring Boot tutorial<\/em>, I have shown you how to set up the <em>Spring Boot development environment<\/em> using Docker and docker-compose. Did you manage to go through all the steps? Let me know in the comments below. Please have a look at the other <a href=\"https:\/\/zaven.co\/blog\/category\/tutorials\/\">tutorials<\/a> on our blog.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do you need to build a simple Spring Boot app with Docker? Keep on reading this Docker and Spring Boot tutorial and find out how to configure the Spring Boot development environment using Docker and docker-compose.<\/p>\n","protected":false},"author":11,"featured_media":1239,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,58],"tags":[138,136,140,139,141,8,137,120],"class_list":["post-1241","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-web-development","tag-docker","tag-docker-and-spring-boot-tutorial","tag-docker-development-environment","tag-spring-boot","tag-spring-boot-app-with-docker","tag-tutorial","tag-tutorials","tag-web-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring Boot Docker tutorial: Initializr, Compose | Zaven Blog<\/title>\n<meta name=\"description\" content=\"Check out our latest Spring Boot Docker tutorial to become familiar with such programming structure. Zaven, awarded company shares knowledge.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Boot Docker tutorial: Initializr, Compose | Zaven Blog\" \/>\n<meta property=\"og:description\" content=\"Check out our latest Spring Boot Docker tutorial to become familiar with such programming structure. Zaven, awarded company shares knowledge.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Zaven Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-11T14:08:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-08T17:55:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/04\/cover_photo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"670\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Slawomir Onyszko\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Slawomir Onyszko\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/\",\"url\":\"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/\",\"name\":\"Spring Boot Docker tutorial: Initializr, Compose | Zaven Blog\",\"isPartOf\":{\"@id\":\"https:\/\/zaven.co\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/04\/cover_photo.png\",\"datePublished\":\"2019-04-11T14:08:25+00:00\",\"dateModified\":\"2025-04-08T17:55:06+00:00\",\"author\":{\"@id\":\"https:\/\/zaven.co\/blog\/#\/schema\/person\/54027190fa6219030f9c4705fa7e0168\"},\"description\":\"Check out our latest Spring Boot Docker tutorial to become familiar with such programming structure. Zaven, awarded company shares knowledge.\",\"breadcrumb\":{\"@id\":\"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/#primaryimage\",\"url\":\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/04\/cover_photo.png\",\"contentUrl\":\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/04\/cover_photo.png\",\"width\":1100,\"height\":670,\"caption\":\"spring boot docker\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/zaven.co\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Docker and Spring Boot tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/zaven.co\/blog\/#website\",\"url\":\"https:\/\/zaven.co\/blog\/\",\"name\":\"Zaven Blog\",\"description\":\"Software development blog. Generative AI, web &amp; mobile applications.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/zaven.co\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/zaven.co\/blog\/#\/schema\/person\/54027190fa6219030f9c4705fa7e0168\",\"name\":\"Slawomir Onyszko\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zaven.co\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4dc8884e2167c9cc97596c4b71c7c250?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4dc8884e2167c9cc97596c4b71c7c250?s=96&d=mm&r=g\",\"caption\":\"Slawomir Onyszko\"},\"description\":\"S\u0142awek is our mobile developer who mostly takes care of creating Android applications. He is constantly enhancing his skills of advanced Android app development and he wants to share this knowledge via Zaven\u2019s blog. In his spare time S\u0142awek enjoys watching a good movie at the cinema.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/mronyszko\"],\"url\":\"https:\/\/zaven.co\/blog\/author\/slawekzaven-pl\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Boot Docker tutorial: Initializr, Compose | Zaven Blog","description":"Check out our latest Spring Boot Docker tutorial to become familiar with such programming structure. Zaven, awarded company shares knowledge.","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:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Spring Boot Docker tutorial: Initializr, Compose | Zaven Blog","og_description":"Check out our latest Spring Boot Docker tutorial to become familiar with such programming structure. Zaven, awarded company shares knowledge.","og_url":"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/","og_site_name":"Zaven Blog","article_published_time":"2019-04-11T14:08:25+00:00","article_modified_time":"2025-04-08T17:55:06+00:00","og_image":[{"width":1100,"height":670,"url":"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/04\/cover_photo.png","type":"image\/png"}],"author":"Slawomir Onyszko","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Slawomir Onyszko","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/","url":"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/","name":"Spring Boot Docker tutorial: Initializr, Compose | Zaven Blog","isPartOf":{"@id":"https:\/\/zaven.co\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/04\/cover_photo.png","datePublished":"2019-04-11T14:08:25+00:00","dateModified":"2025-04-08T17:55:06+00:00","author":{"@id":"https:\/\/zaven.co\/blog\/#\/schema\/person\/54027190fa6219030f9c4705fa7e0168"},"description":"Check out our latest Spring Boot Docker tutorial to become familiar with such programming structure. Zaven, awarded company shares knowledge.","breadcrumb":{"@id":"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/#primaryimage","url":"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/04\/cover_photo.png","contentUrl":"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/04\/cover_photo.png","width":1100,"height":670,"caption":"spring boot docker"},{"@type":"BreadcrumbList","@id":"https:\/\/zaven.co\/blog\/docker-and-spring-boot-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/zaven.co\/blog\/"},{"@type":"ListItem","position":2,"name":"Docker and Spring Boot tutorial"}]},{"@type":"WebSite","@id":"https:\/\/zaven.co\/blog\/#website","url":"https:\/\/zaven.co\/blog\/","name":"Zaven Blog","description":"Software development blog. Generative AI, web &amp; mobile applications.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/zaven.co\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/zaven.co\/blog\/#\/schema\/person\/54027190fa6219030f9c4705fa7e0168","name":"Slawomir Onyszko","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zaven.co\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4dc8884e2167c9cc97596c4b71c7c250?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4dc8884e2167c9cc97596c4b71c7c250?s=96&d=mm&r=g","caption":"Slawomir Onyszko"},"description":"S\u0142awek is our mobile developer who mostly takes care of creating Android applications. He is constantly enhancing his skills of advanced Android app development and he wants to share this knowledge via Zaven\u2019s blog. In his spare time S\u0142awek enjoys watching a good movie at the cinema.","sameAs":["https:\/\/www.linkedin.com\/in\/mronyszko"],"url":"https:\/\/zaven.co\/blog\/author\/slawekzaven-pl\/"}]}},"_links":{"self":[{"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/posts\/1241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/comments?post=1241"}],"version-history":[{"count":42,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/posts\/1241\/revisions"}],"predecessor-version":[{"id":69907,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/posts\/1241\/revisions\/69907"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/media\/1239"}],"wp:attachment":[{"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/media?parent=1241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/categories?post=1241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/tags?post=1241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}