{"id":838,"date":"2023-08-09T10:04:33","date_gmt":"2023-08-09T09:04:33","guid":{"rendered":"https:\/\/dassiorleando.com\/?p=838"},"modified":"2025-01-07T04:33:56","modified_gmt":"2025-01-07T03:33:56","slug":"docker-compose-springboot-mysql","status":"publish","type":"post","link":"https:\/\/dassiorleando.com\/fr\/docker-compose-springboot-mysql\/","title":{"rendered":"Dockerize Spring Boot and MySQL with Docker Compose"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>Docker has revolutionized application deployment by enabling developers to package applications and their dependencies into portable containers. In this comprehensive guide, we&#8217;ll explore how to dockerize a <strong>Spring Boot<\/strong> application with <strong>MySQL<\/strong>, leveraging the power of <strong>Docker<\/strong> and <strong>Docker Compose<\/strong>. By containerizing your Spring Boot application, you can achieve easy deployment, improved portability, scalability, and version control.<\/p>\n\n\n\n<p>The <strong>YouTube Channels<\/strong> in both English (En) and French (Fr) are now accessible, feel free to subscribe by clicking <a href=\"https:\/\/www.youtube.com\/@numericaideas\/channels?sub_confirmation=1\">here<\/a>.<\/p>\n\n\n\n<p><strong>This article was originally posted<\/strong> on the NumericaIdeas tech community blog:&nbsp;<a href=\"https:\/\/blog.numericaideas.com\/docker-compose-springboot-mysql\">https:\/\/blog.numericaideas.com\/docker-compose-springboot-mysql<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Docker?<\/h2>\n\n\n\n<p><strong>Docker<\/strong> is an open-source platform that simplifies application deployment by packaging applications and their dependencies into containers. Containers provide a lightweight, isolated environment that can run consistently across different environments which greatly improves the development and deployment experiences.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Dockerize a Spring Boot Application with MySQL?<\/h2>\n\n\n\n<p>Dockerizing a Spring Boot application with MySQL offers several advantages:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Portability<\/strong>: Docker containers can be deployed on any machine running Docker, eliminating environment-specific issues.<\/li>\n\n\n\n<li><strong>Isolation<\/strong>: Containers provide an isolated environment, ensuring consistent and reliable application execution.<\/li>\n\n\n\n<li><strong>Scalability<\/strong>: Docker containers can be easily scaled horizontally to handle increased demand.<\/li>\n\n\n\n<li><strong>Versioning<\/strong>: Docker images can be versioned, enabling easy management and rollback to previous application versions.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>To follow this guide, ensure you have the following prerequisites:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Docker installed on your machine, <a href=\"https:\/\/docs.docker.com\/get-docker\/\">this guide<\/a> could help.<\/li>\n\n\n\n<li>Java Development Kit (JDK) 17 installed, recent versions could work.<\/li>\n\n\n\n<li>Maven or Gradle build tool installed.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Create a Spring Boot Application<\/h2>\n\n\n\n<p>Before proceeding, let&#8217;s create a basic Spring Boot App with the latest stable release at the time of writing, which is version <strong>3.1.2<\/strong>.<\/p>\n\n\n\n<p>It involves accessing the initializer service at <a href=\"https:\/\/start.spring.io\/\">https:\/\/start.spring.io<\/a>, providing some basic details in regard to the App, selecting the required dependencies then hitting on the <strong>GENERATE<\/strong> button to have the basic structure of the project as follows:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/spring-boot-initializer.png\" alt=\"Spring Boot Initializer\" class=\"wp-image-841\"\/><\/figure><\/div>\n\n\n<p>You can quickly determine the following dependencies that come packaged in the <strong>Maven<\/strong> project:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Spring Data JPA<\/strong>: Persist data in SQL stores with Java Persistence API using Spring Data and Hibernate.<\/li>\n\n\n\n<li><strong>Spring Web<\/strong>: Build web, including RESTful, applications using Spring MVC. Uses Apache Tomcat as the default embedded container.<\/li>\n\n\n\n<li><strong>MySQL Driver<\/strong>: MySQL JDBC driver.<\/li>\n<\/ul>\n\n\n\n<p>Open the generated project in your favorite IDE or editor (I&#8217;m mainly using IntelliJ IDEA and VsCode), from there you can tweak it a bit to have some entities, controllers, and business logic.<\/p>\n\n\n\n<p>Hosted on GitHub, here&#8217;s the <a href=\"https:\/\/github.com\/numerica-ideas\/community\/tree\/master\/docker\/docker-compose-springboot-mysql\">source code<\/a> of the Spring Boot application that we&#8217;ll be using to setup Docker along with a MySQL database.<\/p>\n\n\n\n<p>The <strong><a href=\"https:\/\/github.com\/numerica-ideas\/community\/blob\/master\/docker\/docker-compose-springboot-mysql\/src\/main\/resources\/application.properties\">application.properties<\/a><\/strong> file holds some App configurations, it&#8217;s not uncommon to see sensitive credentials in it, here&#8217;s its content:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\"># Server port\nserver.port=8090\n\n# Datasource connection\nspring.datasource.platform=mysql\nspring.datasource.initialization-mode=always\nspring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect\n\n# Hibernate\nspring.jpa.hibernate.ddl-auto=update\nspring.jpa.hibernate.show-sql=true\n\n# Logging\nlogging.level.org.springframework=ERROR\nlogging.level.com.numericaideas=DEBUG\nlogging.level.org.hibernate.SQL=DEBUG\nlogging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE<\/pre>\n\n\n\n<p>Let&#8217;s build the App to make sure it compiles as expected, the following command must be run from the project root folder:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">.\/mvnw clean install -DskipTests<\/pre>\n\n\n\n<p>At the end of the execution, the <strong>Maven<\/strong> build output should look like this:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/maven-build.png\" alt=\"Maven build\" class=\"wp-image-842\"\/><\/figure><\/div>\n\n\n<p>Other <strong>Bash<\/strong> scripts are available within the project for convenience:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>build.sh<\/code>: to build the project.<\/li>\n\n\n\n<li><code>up.sh<\/code>: to start the project using <strong>Docker Compose<\/strong>.<\/li>\n\n\n\n<li><code>down.sh<\/code>: to shut everything down.<\/li>\n<\/ul>\n\n\n\n<p>For our demo, the port in use is <strong>8090<\/strong> and we have implemented the CRUD operations for the <strong>User<\/strong> entity as well as a <strong>Ping<\/strong> endpoint, we won&#8217;t go deeper on that since it&#8217;s out of scope and you can follow the next sections of this guide with an existing Spring Boot (Maven) project too.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create Docker Image for Spring Boot Application<\/h2>\n\n\n\n<p>The <code><a href=\"https:\/\/github.com\/numerica-ideas\/community\/blob\/master\/docker\/docker-compose-springboot-mysql\/Dockerfile\">Dockerfile<\/a><\/code> should be provided to build an image of the Spring Boot Application, it contains the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\"># Use a base image with Java 17\nFROM openjdk:17\n\n# Copy the JAR package into the image\nARG JAR_FILE=target\/*.jar\nCOPY ${JAR_FILE} app.jar\n\n# Expose the application port\nEXPOSE 8090\n\n# Run the App\nENTRYPOINT [&quot;java&quot;, &quot;-jar&quot;, &quot;\/app.jar&quot;]<\/pre>\n\n\n\n<p>It&#8217;s straightforward, the <code>Dockerfile<\/code> uses an image based on <strong>Java 17<\/strong>, it copies into the image the executable <strong>JAR<\/strong> file that resulted from the build in the previous step, exposes the <strong>port<\/strong> the App is running on, then provides the <strong>entry point<\/strong> which is the bash command to run at the end to start the container.<\/p>\n\n\n\n<p>By building your image with the command <code>docker build .<\/code>, a successful output should be similar to the next image:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/build-app-docker-image.png\" alt=\"Build Spring Boot Docker image\" class=\"wp-image-845\"\/><\/figure><\/div>\n\n\n<p>By this stage, we have the App image and since we&#8217;ll use an official MySQL Docker image, we can manually spin up both components and link them together by using the database credentials to run the App, but to make the process easier we&#8217;ll link their deployments together by using <strong>Docker Compose<\/strong> in the next section.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Docker Compose Spring Boot and MySQL<\/h2>\n\n\n\n<p>Docker Compose simplifies the orchestration of multi-container applications. Create a file named <code>docker-compose.yml<\/code> in your project directory and add the following configuration:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">version: &#039;3.7&#039;\nservices:\n  app:\n    build:\n      context: .\n      dockerfile: Dockerfile\n    ports:\n      - 8090:8090\n    depends_on:\n      mysqldb:\n        condition: service_healthy\n    environment:\n      - SPRING_DATASOURCE_URL=jdbc:mysql:\/\/mysqldb:3306\/${MYSQL_DATABASE}\n      - SPRING_DATASOURCE_USERNAME=root\n      - SPRING_DATASOURCE_PASSWORD=${MYSQL_PASSWORD}\n    networks:\n      - springboot-mysql-network\n  mysqldb:\n    image: mysql:8.0.33\n    ports:\n      - 3306:3306\n    environment:\n      - MYSQL_DATABASE=${MYSQL_DATABASE}\n      - MYSQL_ROOT_PASSWORD=${MYSQL_PASSWORD}\n    volumes:\n      - mysql-data:\/var\/lib\/mysql\n    networks:\n      - springboot-mysql-network\n    healthcheck:\n      test: [&quot;CMD&quot;, &quot;mysqladmin&quot; ,&quot;ping&quot;, &quot;-h&quot;, &quot;localhost&quot;]\n      retries: 10\n      interval: 3s\n      timeout: 30s\nvolumes:\n  mysql-data:\nnetworks:\n  springboot-mysql-network:\n    name: springboot-mysql-network<\/pre>\n\n\n\n<p>This Docker Compose configuration defines two services: <code>app<\/code> for the <strong>Spring Boot Application<\/strong> and <code>mysqldb<\/code> for the <strong>MySQL database<\/strong>. The <code>app<\/code> service builds the image based on the <a href=\"https:\/\/github.com\/numerica-ideas\/community\/blob\/master\/docker\/docker-compose-springboot-mysql\/Dockerfile\">Dockerfile<\/a> in the project&#8217;s root directory. The <code>mysqldb<\/code> service uses the official <strong>MySQL<\/strong> image and sets the environment variables for the database configuration. The <code>depends_on<\/code> attribute ensures that the Spring Boot application starts after the MySQL database in order to guarantee dependency ordering. Finally, the <code>healthcheck<\/code> makes sure the MySQL service is ready to accept connections before running the App.<\/p>\n\n\n\n<p>For the App to connect itself to the MySQL database, as an enhanced security measure, we provided the database credentials as environment variables via the services&#8217; environment attributes so these are textually hidden from the project source code:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>MYSQL_DATABASE<\/strong>: The database name.<\/li>\n\n\n\n<li><strong>MYSQL_PASSWORD<\/strong>: The database root&#8217;s password, we use the root user account for simplicity only.<\/li>\n<\/ul>\n\n\n\n<p>The environment attributes present in the <strong>app<\/strong> service are provided as environment variables to the App container at run time, we are talking about:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SPRING_DATASOURCE_URL<\/li>\n\n\n\n<li>SPRING_DATASOURCE_USERNAME<\/li>\n\n\n\n<li>SPRING_DATASOURCE_PASSWORD<\/li>\n<\/ul>\n\n\n\n<p>Spring Boot automatically assigns these variables to the related <strong>application.properties<\/strong> configurations listed below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>spring.datasource.url<\/li>\n\n\n\n<li>spring.datasource.username<\/li>\n\n\n\n<li>spring.datasource.password<\/li>\n<\/ul>\n\n\n\n<p>Meaning we don&#8217;t have to provide these manually into the <strong>application.properties<\/strong> file, <a href=\"https:\/\/docs.spring.io\/spring-cloud-skipper\/docs\/1.0.0.BUILD-SNAPSHOT\/reference\/html\/skipper-database-configuration.html\">read more here<\/a>.<\/p>\n\n\n\n<p>This Docker Compose configuration defines two services: <code>app<\/code> for the <strong>Spring Boot Application<\/strong> and <code>mysqldb<\/code> for the <strong>MySQL database<\/strong>. The <code>app<\/code> service builds the image based on the <a href=\"https:\/\/github.com\/numerica-ideas\/community\/blob\/master\/docker\/docker-compose-springboot-mysql\/Dockerfile\">Dockerfile<\/a> in the project&#8217;s root directory. The <code>mysqldb<\/code> service uses the official <strong>MySQL<\/strong> image and sets the environment variables for the database configuration. The <code>depends_on<\/code> attribute ensures that the Spring Boot application starts after the MySQL database in order to guarantee dependency ordering. Finally, the <code>healthcheck<\/code> makes sure the MySQL service is ready to accept connections before running the App.<\/p>\n\n\n\n<p>For the App to connect itself to the MySQL database, as an enhanced security measure, we provided the database credentials as environment variables via the services&#8217; environment attributes so these are textually hidden from the project source code:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>MYSQL_DATABASE<\/strong>: The database name.<\/li>\n\n\n\n<li><strong>MYSQL_PASSWORD<\/strong>: The database root&#8217;s password, we use the root user account for simplicity only.<\/li>\n<\/ul>\n\n\n\n<p>The environment attributes present in the <strong>app<\/strong> service are provided as environment variables to the App container at run time, we are talking about:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SPRING_DATASOURCE_URL<\/li>\n\n\n\n<li>SPRING_DATASOURCE_USERNAME<\/li>\n\n\n\n<li>SPRING_DATASOURCE_PASSWORD<\/li>\n<\/ul>\n\n\n\n<p>Spring Boot automatically assigns these variables to the related <strong>application.properties<\/strong> configurations listed below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>spring.datasource.url<\/li>\n\n\n\n<li>spring.datasource.username<\/li>\n\n\n\n<li>spring.datasource.password<\/li>\n<\/ul>\n\n\n\n<p>Meaning we don&#8217;t have to provide these manually into the <strong>application.properties<\/strong> file, <a href=\"https:\/\/docs.spring.io\/spring-cloud-skipper\/docs\/1.0.0.BUILD-SNAPSHOT\/reference\/html\/skipper-database-configuration.html\">read more here<\/a>.<\/p>\n\n\n\n<p>This Docker Compose configuration defines two services: <code>app<\/code> for the <strong>Spring Boot Application<\/strong> and <code>mysqldb<\/code> for the <strong>MySQL database<\/strong>. The <code>app<\/code> service builds the image based on the <a href=\"https:\/\/github.com\/numerica-ideas\/community\/blob\/master\/docker\/docker-compose-springboot-mysql\/Dockerfile\">Dockerfile<\/a> in the project&#8217;s root directory. The <code>mysqldb<\/code> service uses the official <strong>MySQL<\/strong> image and sets the environment variables for the database configuration. The <code>depends_on<\/code> attribute ensures that the Spring Boot application starts after the MySQL database in order to guarantee dependency ordering. Finally, the <code>healthcheck<\/code> makes sure the MySQL service is ready to accept connections before running the App.<\/p>\n\n\n\n<p>For the App to connect itself to the MySQL database, as an enhanced security measure, we provided the database credentials as environment variables via the services&#8217; environment attributes so these are textually hidden from the project source code:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>MYSQL_DATABASE<\/strong>: The database name.<\/li>\n\n\n\n<li><strong>MYSQL_PASSWORD<\/strong>: The database root&#8217;s password, we use the root user account for simplicity only.<\/li>\n<\/ul>\n\n\n\n<p>The environment attributes present in the <strong>app<\/strong> service are provided as environment variables to the App container at run time, we are talking about:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SPRING_DATASOURCE_URL<\/li>\n\n\n\n<li>SPRING_DATASOURCE_USERNAME<\/li>\n\n\n\n<li>SPRING_DATASOURCE_PASSWORD<\/li>\n<\/ul>\n\n\n\n<p>Spring Boot automatically assigns these variables to the related <strong>application.properties<\/strong> configurations listed below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>spring.datasource.url<\/li>\n\n\n\n<li>spring.datasource.username<\/li>\n\n\n\n<li>spring.datasource.password<\/li>\n<\/ul>\n\n\n\n<p>Meaning we don&#8217;t have to provide these manually into the <strong>application.properties<\/strong> file, <a href=\"https:\/\/docs.spring.io\/spring-cloud-skipper\/docs\/1.0.0.BUILD-SNAPSHOT\/reference\/html\/skipper-database-configuration.html\">read more here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Run the Dockerized Application<\/h2>\n\n\n\n<p>To run the App via <strong>Docker Compose<\/strong>, open a terminal, navigate to the project&#8217;s root directory, and execute the following command in which we provide the <strong>environment variables<\/strong> directly:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">MYSQL_DATABASE=mydatabase MYSQL_PASSWORD=rootpassword docker-compose up<\/pre>\n\n\n\n<p>In case you would like to provide the environment variables from a hidden <code>.env<\/code> file, feel free to create it from the <code>.env.sample<\/code> file and put it close to the <code>docker-compose.yml<\/code> within the project.<\/p>\n\n\n\n<p>This being done, the command to run will change a bit to the following:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">docker-compose up<\/pre>\n\n\n\n<p>Docker Compose will build the Spring Boot and MySQL images, create the containers, and start them. You&#8217;ll see logs from both the application and the database. To stop the containers, press Ctrl+C.<\/p>\n\n\n\n<p>Using <strong>Docker Desktop<\/strong> enables you to view a nice summary of your Docker state in which we can see our running containers as illustrated below:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/docker-desktop-running-containers.png\" alt=\"Running containers on Docker Desktop\" class=\"wp-image-848\"\/><\/figure><\/div>\n\n\n<p>The complete source code of the project is available on <a href=\"https:\/\/github.com\/numerica-ideas\/community\/tree\/master\/docker\/docker-compose-springboot-mysql\">GitHub<\/a>.<\/p>\n\n\n\n<p>Open POSTMAN and <strong>create<\/strong> a POST request to the URL <code>localhost:8090\/api\/users<\/code> with a random user object to be persisted in the DB:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/test-api-create-user-1024x559.png\" alt=\"Test API: create a user\" class=\"wp-image-849\"\/><\/figure><\/div>\n\n\n<p>Let&#8217;s <strong>list all users<\/strong> which includes the one we just created:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/test-api-list-users-1024x605.png\" alt=\"Test API: list all users\" class=\"wp-image-850\"\/><\/figure><\/div>\n\n\n<p>A <strong>ping<\/strong> endpoint is also available:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/test-api-ping-1024x479.png\" alt=\"Test API: ping endpoint\" class=\"wp-image-851\"\/><\/figure><\/div>\n\n\n<p>If you are interested in related content, take a look at the following which explains how to <a href=\"https:\/\/blog.numericaideas.com\/quickly-dockerizing-nodejs\">Quickly Dockerizing NodeJS Application using docker init command<\/a>.<\/p>\n\n\n\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\n\n\n\n<p>We have just started our journey to build a network of professionals to grow even more our free knowledge-sharing community that\u2019ll give you a chance to learn interesting things about topics like cloud computing, software development, and software architectures while keeping the door open to more opportunities.<\/p>\n\n\n\n<p>Does this speak to you? If <strong>YES<\/strong>, feel free to <a href=\"https:\/\/discord.numericaideas.com\/\">Join our Discord Server<\/a> to stay in touch with the community and be part of independently organized events.<\/p>\n\n\n\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Dockerizing a Spring Boot application with MySQL using Docker and Docker Compose simplifies the deployment process, improves portability, and enables scalability. By following the steps outlined in this guide, you can package your Spring Boot application and MySQL database into separate containers and deploy them as a cohesive application stack. With Docker, you can achieve consistent application execution across different environments, easily scale your application, and simplify version control. Docker Compose streamlines the management of multi-container applications, allowing you to define, configure, and deploy complex systems effortlessly.<\/p>\n\n\n\n<p>Thanks for reading this article. Like, recommend, and share if you enjoyed it. Follow us on <a href=\"https:\/\/www.facebook.com\/numericaideas\">Facebook<\/a>, <a href=\"https:\/\/twitter.com\/numericaideas\">Twitter<\/a>, and <a href=\"https:\/\/www.linkedin.com\/company\/numericaideas\">LinkedIn<\/a> for more content.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Docker has revolutionized application deployment by enabling developers to package applications and their dependencies into portable containers. In this comprehensive guide, we&#8217;ll explore how to dockerize a Spring Boot application with MySQL, leveraging the power of Docker and Docker Compose. By containerizing your Spring Boot application, you can achieve easy deployment, improved portability, scalability, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54,57],"tags":[53,55,30,56,58],"class_list":["post-838","post","type-post","status-publish","format-standard","hentry","category-docker","category-spring-boot","tag-devops","tag-docker","tag-java","tag-solutions-architecture","tag-spring-boot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Dockerize Spring Boot and MySQL with Docker Compose - Orleando Dassi<\/title>\n<meta name=\"description\" content=\"Let&#039;s explore how to dockerize a Spring Boot Application with MySQL by leveraging the power of Docker and Docker Compose to achieve easy deployment, improved portability, scalability, and version control.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/\" \/>\n<meta property=\"og:locale\" content=\"fr_CA\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dockerize Spring Boot and MySQL with Docker Compose - Orleando Dassi\" \/>\n<meta property=\"og:description\" content=\"Let&#039;s explore how to dockerize a Spring Boot Application with MySQL by leveraging the power of Docker and Docker Compose to achieve easy deployment, improved portability, scalability, and version control.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/\" \/>\n<meta property=\"og:site_name\" content=\"Orleando Dassi\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-09T09:04:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-07T03:33:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/Dockerize-Spring-Boot-Application-with-MySQL.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1366\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Orl\u00e9ando Dassi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dassiorleando\" \/>\n<meta name=\"twitter:site\" content=\"@dassiorleando\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Orl\u00e9ando Dassi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/dassiorleando.com\/docker-compose-springboot-mysql\/\"},\"author\":{\"name\":\"Orl\u00e9ando Dassi\",\"@id\":\"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e\"},\"headline\":\"Dockerize Spring Boot and MySQL with Docker Compose\",\"datePublished\":\"2023-08-09T09:04:33+00:00\",\"dateModified\":\"2025-01-07T03:33:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/dassiorleando.com\/docker-compose-springboot-mysql\/\"},\"wordCount\":1800,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e\"},\"image\":{\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/spring-boot-initializer.png\",\"keywords\":[\"DevOps\",\"Docker\",\"JAVA\",\"Solutions Architecture\",\"Spring Boot\"],\"articleSection\":[\"Docker\",\"Spring Boot\"],\"inLanguage\":\"fr-CA\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dassiorleando.com\/docker-compose-springboot-mysql\/\",\"url\":\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/\",\"name\":\"Dockerize Spring Boot and MySQL with Docker Compose - Orleando Dassi\",\"isPartOf\":{\"@id\":\"https:\/\/dassiorleando.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/spring-boot-initializer.png\",\"datePublished\":\"2023-08-09T09:04:33+00:00\",\"dateModified\":\"2025-01-07T03:33:56+00:00\",\"description\":\"Let's explore how to dockerize a Spring Boot Application with MySQL by leveraging the power of Docker and Docker Compose to achieve easy deployment, improved portability, scalability, and version control.\",\"breadcrumb\":{\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#breadcrumb\"},\"inLanguage\":\"fr-CA\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-CA\",\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#primaryimage\",\"url\":\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/spring-boot-initializer.png\",\"contentUrl\":\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/spring-boot-initializer.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dassiorleando.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dockerize Spring Boot and MySQL with Docker Compose\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dassiorleando.com\/#website\",\"url\":\"https:\/\/dassiorleando.com\/\",\"name\":\"Orleando Dassi\",\"description\":\"My personal portfolio and resume\",\"publisher\":{\"@id\":\"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dassiorleando.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-CA\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e\",\"name\":\"Orl\u00e9ando Dassi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-CA\",\"@id\":\"https:\/\/dassiorleando.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2025\/01\/Orleando-Dassi-Consultant-Quebec.webp\",\"contentUrl\":\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2025\/01\/Orleando-Dassi-Consultant-Quebec.webp\",\"width\":1643,\"height\":1747,\"caption\":\"Orl\u00e9ando Dassi\"},\"logo\":{\"@id\":\"https:\/\/dassiorleando.com\/#\/schema\/person\/image\/\"},\"description\":\"I'm a Solutions Architect with 10 years of experience who is constantly learning while impacting the community by producing technical articles\/videos, building projects, and conducting tech mentoring\/coaching sessions. What describes me the most is my flexibility.\",\"sameAs\":[\"https:\/\/dassiorleando.com\/\",\"https:\/\/www.instagram.com\/dassiorleando\/\",\"https:\/\/www.linkedin.com\/in\/dassi-orleando-257b04ab\/\",\"https:\/\/x.com\/dassiorleando\",\"https:\/\/www.youtube.com\/@dassiorleando\"],\"url\":\"https:\/\/dassiorleando.com\/fr\/author\/dassiorleando\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dockerize Spring Boot and MySQL with Docker Compose - Orleando Dassi","description":"Let's explore how to dockerize a Spring Boot Application with MySQL by leveraging the power of Docker and Docker Compose to achieve easy deployment, improved portability, scalability, and version control.","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:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/","og_locale":"fr_CA","og_type":"article","og_title":"Dockerize Spring Boot and MySQL with Docker Compose - Orleando Dassi","og_description":"Let's explore how to dockerize a Spring Boot Application with MySQL by leveraging the power of Docker and Docker Compose to achieve easy deployment, improved portability, scalability, and version control.","og_url":"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/","og_site_name":"Orleando Dassi","article_published_time":"2023-08-09T09:04:33+00:00","article_modified_time":"2025-01-07T03:33:56+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/Dockerize-Spring-Boot-Application-with-MySQL.png","type":"image\/png"}],"author":"Orl\u00e9ando Dassi","twitter_card":"summary_large_image","twitter_creator":"@dassiorleando","twitter_site":"@dassiorleando","twitter_misc":{"Written by":"Orl\u00e9ando Dassi","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#article","isPartOf":{"@id":"https:\/\/dassiorleando.com\/docker-compose-springboot-mysql\/"},"author":{"name":"Orl\u00e9ando Dassi","@id":"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e"},"headline":"Dockerize Spring Boot and MySQL with Docker Compose","datePublished":"2023-08-09T09:04:33+00:00","dateModified":"2025-01-07T03:33:56+00:00","mainEntityOfPage":{"@id":"https:\/\/dassiorleando.com\/docker-compose-springboot-mysql\/"},"wordCount":1800,"commentCount":0,"publisher":{"@id":"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e"},"image":{"@id":"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/spring-boot-initializer.png","keywords":["DevOps","Docker","JAVA","Solutions Architecture","Spring Boot"],"articleSection":["Docker","Spring Boot"],"inLanguage":"fr-CA","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dassiorleando.com\/docker-compose-springboot-mysql\/","url":"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/","name":"Dockerize Spring Boot and MySQL with Docker Compose - Orleando Dassi","isPartOf":{"@id":"https:\/\/dassiorleando.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#primaryimage"},"image":{"@id":"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/spring-boot-initializer.png","datePublished":"2023-08-09T09:04:33+00:00","dateModified":"2025-01-07T03:33:56+00:00","description":"Let's explore how to dockerize a Spring Boot Application with MySQL by leveraging the power of Docker and Docker Compose to achieve easy deployment, improved portability, scalability, and version control.","breadcrumb":{"@id":"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#breadcrumb"},"inLanguage":"fr-CA","potentialAction":[{"@type":"ReadAction","target":["https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/"]}]},{"@type":"ImageObject","inLanguage":"fr-CA","@id":"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#primaryimage","url":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/spring-boot-initializer.png","contentUrl":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/08\/spring-boot-initializer.png"},{"@type":"BreadcrumbList","@id":"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dassiorleando.com\/"},{"@type":"ListItem","position":2,"name":"Dockerize Spring Boot and MySQL with Docker Compose"}]},{"@type":"WebSite","@id":"https:\/\/dassiorleando.com\/#website","url":"https:\/\/dassiorleando.com\/","name":"Orleando Dassi","description":"My personal portfolio and resume","publisher":{"@id":"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dassiorleando.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-CA"},{"@type":["Person","Organization"],"@id":"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e","name":"Orl\u00e9ando Dassi","image":{"@type":"ImageObject","inLanguage":"fr-CA","@id":"https:\/\/dassiorleando.com\/#\/schema\/person\/image\/","url":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2025\/01\/Orleando-Dassi-Consultant-Quebec.webp","contentUrl":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2025\/01\/Orleando-Dassi-Consultant-Quebec.webp","width":1643,"height":1747,"caption":"Orl\u00e9ando Dassi"},"logo":{"@id":"https:\/\/dassiorleando.com\/#\/schema\/person\/image\/"},"description":"I'm a Solutions Architect with 10 years of experience who is constantly learning while impacting the community by producing technical articles\/videos, building projects, and conducting tech mentoring\/coaching sessions. What describes me the most is my flexibility.","sameAs":["https:\/\/dassiorleando.com\/","https:\/\/www.instagram.com\/dassiorleando\/","https:\/\/www.linkedin.com\/in\/dassi-orleando-257b04ab\/","https:\/\/x.com\/dassiorleando","https:\/\/www.youtube.com\/@dassiorleando"],"url":"https:\/\/dassiorleando.com\/fr\/author\/dassiorleando\/"}]}},"_links":{"self":[{"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/posts\/838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/comments?post=838"}],"version-history":[{"count":1,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/posts\/838\/revisions"}],"predecessor-version":[{"id":883,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/posts\/838\/revisions\/883"}],"wp:attachment":[{"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/media?parent=838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/categories?post=838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/tags?post=838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}