{"id":2286,"date":"2026-07-20T12:43:14","date_gmt":"2026-07-20T10:43:14","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/how-to-deploy-spring-boot-application-with-mysql-database-with-docker\/"},"modified":"2026-08-26T21:13:57","modified_gmt":"2026-08-26T19:13:57","slug":"how-to-deploy-spring-boot-application-with-mysql-database-with-docker","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/how-to-deploy-spring-boot-application-with-mysql-database-with-docker\/","title":{"rendered":"How to Deploy Spring Boot Application with MySQL Database with Docker"},"content":{"rendered":"<p><!-- ktg-updated-banner --><\/p>\n<p><em>Updated August 2026 \u2014 full tutorial restored for this URL.<\/em><\/p>\n<p>This tutorial shows how to run a <strong>Spring Boot<\/strong> API and <strong>MySQL<\/strong> together with <strong>Docker Compose<\/strong> \u2014 the setup I use for demos and simple VPS deploys.<\/p>\n<p>See also: <a href=\"https:\/\/kindsonthegenius.com\/blog\/introduction-to-multi-stage-dockerfile-with-springboot-and-postgresql-example\/\">Multi-stage Dockerfile with Spring Boot and PostgreSQL<\/a>.<\/p>\n<ol>\n<li><a href=\"#t1\">Prerequisites<\/a><\/li>\n<li><a href=\"#t2\">application.properties for containers<\/a><\/li>\n<li><a href=\"#t3\">Dockerfile<\/a><\/li>\n<li><a href=\"#t4\">docker-compose.yml<\/a><\/li>\n<li><a href=\"#t5\">Build, run, verify<\/a><\/li>\n<\/ol>\n<p><strong id=\"t1\">1. Prerequisites<\/strong><\/p>\n<ul>\n<li>Docker + Docker Compose installed<\/li>\n<li>A Spring Boot app that already talks to MySQL locally<\/li>\n<\/ul>\n<p><strong id=\"t2\">2. application.properties for containers<\/strong><\/p>\n<pre><code>spring.datasource.url=jdbc:mysql:\/\/mysql:3306\/appdb?createDatabaseIfNotExist=true&amp;useSSL=false&amp;allowPublicKeyRetrieval=true\nspring.datasource.username=app\nspring.datasource.password=secret\nspring.jpa.hibernate.ddl-auto=update\nserver.port=8080\n<\/code><\/pre>\n<p>Hostname <code>mysql<\/code> matches the Compose service name (Docker DNS).<\/p>\n<p><strong id=\"t3\">3. Dockerfile<\/strong><\/p>\n<pre><code>FROM eclipse-temurin:17-jdk AS build\nWORKDIR \/app\nCOPY . .\nRUN .\/mvnw -DskipTests package\n\nFROM eclipse-temurin:17-jre\nWORKDIR \/app\nCOPY --from=build \/app\/target\/*.jar app.jar\nEXPOSE 8080\nENTRYPOINT [\"java\",\"-jar\",\"\/app\/app.jar\"]\n<\/code><\/pre>\n<p><strong id=\"t4\">4. docker-compose.yml<\/strong><\/p>\n<pre><code>services:\n  mysql:\n    image: mysql:8.0\n    environment:\n      MYSQL_DATABASE: appdb\n      MYSQL_USER: app\n      MYSQL_PASSWORD: secret\n      MYSQL_ROOT_PASSWORD: rootsecret\n    ports:\n      - \"3306:3306\"\n    volumes:\n      - mysql_data:\/var\/lib\/mysql\n    healthcheck:\n      test: [\"CMD\", \"mysqladmin\", \"ping\", \"-h\", \"localhost\"]\n      interval: 5s\n      retries: 10\n\n  api:\n    build: .\n    ports:\n      - \"8080:8080\"\n    depends_on:\n      mysql:\n        condition: service_healthy\n\nvolumes:\n  mysql_data:\n<\/code><\/pre>\n<p><strong id=\"t5\">5. Build, run, verify<\/strong><\/p>\n<pre><code>docker compose up --build\ncurl http:\/\/localhost:8080\/actuator\/health   # or your own endpoint\n<\/code><\/pre>\n<p>Common fixes: wait for MySQL healthy before the app starts; match JDBC URL host to service name; persist data with a named volume.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Updated August 2026 \u2014 full tutorial restored for this URL. This tutorial shows how to run a Spring Boot API and MySQL together with Docker &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[85],"tags":[],"class_list":["post-2286","post","type-post","status-publish","format-standard","hentry","category-java"],"acf":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/2286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=2286"}],"version-history":[{"count":2,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/2286\/revisions"}],"predecessor-version":[{"id":2449,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/2286\/revisions\/2449"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=2286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=2286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=2286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}