{"id":17176,"date":"2023-07-25T01:46:14","date_gmt":"2023-07-25T01:46:14","guid":{"rendered":"http:\/\/64bc5e155f7dc3001b8b9b60"},"modified":"2025-01-07T04:36:15","modified_gmt":"2025-01-07T03:36:15","slug":"docker-compose-springboot-mysql-2","status":"publish","type":"post","link":"https:\/\/dassiorleando.com\/fr\/docker-compose-springboot-mysql-2\/","title":{"rendered":"Dockerize Spring Boot and MySQL with Docker Compose"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"introduction\">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<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\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\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n<\/blockquote>\n\n\n<div class=\"vlp-link-container vlp-layout-basic wp-block-visual-link-preview-link\"><a href=\"https:\/\/www.youtube.com\/@numericaideas\/channels?sub_confirmation=1\" class=\"vlp-link\" title=\"Numerica Ideas\" rel=\"nofollow\" target=\"_blank\"><\/a><div class=\"vlp-layout-zone-side\"><div class=\"vlp-block-2 vlp-link-image\"><img decoding=\"async\" src=\"https:\/\/yt3.googleusercontent.com\/klwPa3fnccvxnvUjmfGmcdJDeX8J7BMbRraxiH69WeLx6qr3fQdxYSGN37vKE4jBCqGX5pZCgQ=s900-c-k-c0x00ffffff-no-rj\" style=\"max-width: 150px; max-height: 150px\" \/><\/div><\/div><div class=\"vlp-layout-zone-main\"><div class=\"vlp-block-0 vlp-link-title\">Numerica Ideas<\/div><div class=\"vlp-block-1 vlp-link-summary\">NumericaIdeas is a technical community that creates opportunities for IT professionals, where you\u2019ll secure your dream job, and indeed the group through which you can develop your hard and soft skills at your own pace. Our motto is \u201cDiscover, Learn, Build, &amp; Share\u201d \ud83d\ude80 \ud83d\udca1 La cha\u00eene est aussi disponi\u2026<\/div><\/div><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"understanding-docker-compose\">What is Docker Compose?<\/h2>\n\n\n\n<p>Docker Compose stands as an indispensable tool. This extension of Docker offers the ability to define and manage multi-container applications using simple configuration files written in YAML. Instead of manually managing each container individually, Docker Compose allows the declaration of services, networks, and volumes within a single file, significantly simplifying the deployment process.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advantages-of-using-docker-compose\">Why use Docker Compose?<\/h2>\n\n\n\n<p><strong>Docker Compose<\/strong> presents several significant advantages in the deployment and management of multi-container applications. Here are some of these benefits:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Simplicity of Configuration:<\/strong>&nbsp;Docker Compose uses simple YAML configuration files to define the structure of applications. This approach makes the configuration and management of services, networks, and volumes easier.<\/li>\n\n\n\n<li><strong>Facilitated Orchestration:<\/strong>&nbsp;With Docker Compose, it becomes easy to declare and coordinate multiple services and containers within a single application. This simplifies the orchestration of interconnected components.<\/li>\n\n\n\n<li><strong>Rapid Deployment:<\/strong>&nbsp;Using a single configuration file, Docker Compose provides an efficient method to quickly deploy applications with all their necessary components. This speeds up the development and testing process.<\/li>\n\n\n\n<li><strong>Environment Isolation:<\/strong>&nbsp;Docker Compose configuration files can be tailored for different environments such as development, production, or testing. This allows effective isolation of settings and configurations specific to each phase of an application&#8217;s lifecycle.<\/li>\n<\/ul>\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\/\" rel=\"nofollow\">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\" id=\"create-a-spring-boot-application\">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\/\" rel=\"nofollow\">https:\/\/start.spring.io<\/a>, providing some basic details regarding 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\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.numericaideas.com\/2023\/07\/spring-boot-initializer.png\" alt=\"Dockerize Spring Boot and MySQL with Docker Compose\"\/><figcaption class=\"wp-element-caption\">Spring Boot Initializer<\/figcaption><\/figure>\n\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 set up 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# Datasource connection\nspring.datasource.platform=mysql\nspring.datasource.initialization-mode=always\nspring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect\n# Hibernate\nspring.jpa.hibernate.ddl-auto=update\nspring.jpa.hibernate.show-sql=true\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\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.numericaideas.com\/2023\/07\/maven-build.png\" alt=\"Dockerize Spring Boot and MySQL with Docker Compose\"\/><figcaption class=\"wp-element-caption\">Maven build<\/figcaption><\/figure>\n\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\" id=\"create-docker-image-for-spring-boot-application\">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# Copy the JAR package into the image\nARG JAR_FILE=target\/*.jar\nCOPY ${JAR_FILE} app.jar\n# Expose the application port\nEXPOSE 8090\n# Run the App\nENTRYPOINT [\"java\", \"-jar\", \"\/app.jar\"]<\/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, and 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\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.numericaideas.com\/2023\/07\/build-app-docker-image.png\" alt=\"Dockerize Spring Boot and MySQL with Docker Compose\"\/><figcaption class=\"wp-element-caption\">Build Spring Boot Docker image<\/figcaption><\/figure>\n\n\n\n<p>By this stage, we have the App image and since we&#8217;ll use <a href=\"https:\/\/hub.docker.com\/_\/mysql\" target=\"_blank\" rel=\"noreferrer noopener\">the official MySQL Docker image<\/a>, 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<p><iframe style=\"border-radius: 4px; border: 2px solid #e5e7eb; margin: 0; background-color: transparent;\" src=\"https:\/\/embeds.beehiiv.com\/6e19a1f8-8d19-4ec9-9ed7-ca858ff7ca76\" width=\"100%\" height=\"320\" frameborder=\"0\" scrolling=\"no\" data-test-id=\"beehiiv-embed\">&amp;lt;!&#8211;kg-card-end: html&#8211;> &amp;lt;h2 id=&#8221;docker-compose-spring-boot-and-mysql&#8221;>Docker Compose Spring Boot and MySQL&amp;lt;\/h2> &amp;lt;p>Docker Compose simplifies the orchestration of multi-container applications. Create a file named &amp;lt;code>docker-compose.yml&amp;lt;\/code> in your project directory and add the following configuration:&amp;lt;\/p> &amp;lt;pre>&amp;lt;code>version: &#8216;3.7&#8217;nservices:n  app:n    build:n      context: .n      dockerfile: Dockerfilen    ports:n      &#8211; 8090:8090n    depends_on:n      mysqldb:n        condition: service_healthyn    environment:n      &#8211; SPRING_DATASOURCE_URL=jdbc:mysql:\/\/mysqldb:3306\/${MYSQL_DATABASE}n      &#8211; SPRING_DATASOURCE_USERNAME=rootn      &#8211; SPRING_DATASOURCE_PASSWORD=${MYSQL_PASSWORD}n    networks:n      &#8211; springboot-mysql-networkn  mysqldb:n    image: mysql:8.0.33n    ports:n      &#8211; 3306:3306n    environment:n      &#8211; MYSQL_DATABASE=${MYSQL_DATABASE}n      &#8211; MYSQL_ROOT_PASSWORD=${MYSQL_PASSWORD}n    volumes:n      &#8211; mysql-data:\/var\/lib\/mysqln    networks:n      &#8211; springboot-mysql-networkn    healthcheck:n      test: [&#8220;CMD&#8221;, &#8220;mysqladmin&#8221; ,&#8221;ping&#8221;, &#8220;-h&#8221;, &#8220;localhost&#8221;]n      retries: 10n      interval: 3sn      timeout: 30snvolumes:n  mysql-data:nnetworks:n  springboot-mysql-network:n    name: springboot-mysql-network&amp;lt;\/code>&amp;lt;\/pre> &amp;lt;p>This Docker Compose configuration defines two services: &amp;lt;code>app&amp;lt;\/code> for the &amp;lt;strong>Spring Boot Application&amp;lt;\/strong> and &amp;lt;code>mysqldb&amp;lt;\/code> for the &amp;lt;strong>MySQL database&amp;lt;\/strong>. The &amp;lt;code>app&amp;lt;\/code> service builds the image based on the &amp;lt;a href=&#8221;https:\/\/github.com\/numerica-ideas\/community\/blob\/master\/docker\/docker-compose-springboot-mysql\/Dockerfile&#8221;>Dockerfile&amp;lt;\/a> in the project&#8217;s root directory. The &amp;lt;code>mysqldb&amp;lt;\/code> service uses the official &amp;lt;strong>MySQL&amp;lt;\/strong> image and sets the environment variables for the database configuration. The &amp;lt;code>depends_on&amp;lt;\/code> attribute ensures that the Spring Boot application starts after the MySQL database in order to guarantee dependency ordering. Finally, the &amp;lt;code>healthcheck&amp;lt;\/code> makes sure the MySQL service is ready to accept connections before running the App.&amp;lt;\/p> &amp;lt;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:&amp;lt;\/p> &amp;lt;ul> &amp;lt;li>&amp;lt;strong>MYSQL_DATABASE&amp;lt;\/strong>: The database name.&amp;lt;\/li> &amp;lt;li>&amp;lt;strong>MYSQL_PASSWORD&amp;lt;\/strong>: The database root&#8217;s password, we use the root user account for simplicity only.&amp;lt;\/li> &amp;lt;\/ul> &amp;lt;p>The environment attributes present in the &amp;lt;strong>app&amp;lt;\/strong> service are provided as environment variables to the App container at run time, we are talking about:&amp;lt;\/p> &amp;lt;ul> &amp;lt;li>SPRING_DATASOURCE_URL&amp;lt;\/li> &amp;lt;li>SPRING_DATASOURCE_USERNAME&amp;lt;\/li> &amp;lt;li>SPRING_DATASOURCE_PASSWORD&amp;lt;\/li> &amp;lt;\/ul> &amp;lt;p>Spring Boot automatically assigns these variables to the related &amp;lt;strong>application.properties&amp;lt;\/strong> configurations listed below:&amp;lt;\/p> &amp;lt;ul> &amp;lt;li>spring.datasource.url&amp;lt;\/li> &amp;lt;li>spring.datasource.username&amp;lt;\/li> &amp;lt;li>spring.datasource.password&amp;lt;\/li> &amp;lt;\/ul> &amp;lt;p>Meaning we don&#8217;t have to provide these manually into the &amp;lt;strong>application.properties&amp;lt;\/strong> file, &amp;lt;a href=&#8221;https:\/\/docs.spring.io\/spring-cloud-skipper\/docs\/1.0.0.BUILD-SNAPSHOT\/reference\/html\/skipper-database-configuration.html&#8221; rel=&#8221;nofollow&#8221;>read more here&amp;lt;\/a>.&amp;lt;\/p> &amp;lt;h2 id=&#8221;run-the-dockerized-application&#8221;>Run the Dockerized Application&amp;lt;\/h2> &amp;lt;p>To run the App via &amp;lt;strong>Docker Compose&amp;lt;\/strong>, open a terminal, navigate to the project&#8217;s root directory, and execute the following command in which we provide the &amp;lt;strong>environment variables&amp;lt;\/strong> directly:&amp;lt;\/p> &amp;lt;pre>&amp;lt;code>MYSQL_DATABASE=mydatabase MYSQL_PASSWORD=rootpassword docker-compose up&amp;lt;\/code>&amp;lt;\/pre> &amp;lt;p>In case you would like to provide the environment variables from a hidden &amp;lt;code>.env&amp;lt;\/code> file, feel free to create it from the &amp;lt;code>.env.sample&amp;lt;\/code> file and put it close to the &amp;lt;code>docker-compose.yml&amp;lt;\/code> within the project.&amp;lt;\/p> &amp;lt;p>This being done, the command to run will change a bit to the following:&amp;lt;\/p> &amp;lt;pre>&amp;lt;code>docker-compose up&amp;lt;\/code>&amp;lt;\/pre> &amp;lt;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.&amp;lt;\/p> &amp;lt;p>Using &amp;lt;strong>Docker Desktop&amp;lt;\/strong> enables you to view a nice summary of your Docker state in which we can see our running containers as illustrated below:&amp;lt;\/p> &amp;lt;figure class=&#8221;kg-card kg-image-card kg-width-wide kg-card-hascaption&#8221;>&amp;lt;img src=&#8221;https:\/\/assets.numericaideas.com\/2023\/07\/docker-desktop-running-containers.png&#8221; class=&#8221;kg-image&#8221; alt=&#8221;Dockerize Spring Boot and MySQL with Docker Compose&#8221; \/> &amp;lt;figcaption>Running containers on Docker Desktop&amp;lt;\/figcaption> &amp;lt;p>&amp;lt;\/p>&amp;lt;\/figure> &amp;lt;p>The complete source code of the project is available on &amp;lt;a href=&#8221;https:\/\/github.com\/numerica-ideas\/community\/tree\/master\/docker\/docker-compose-springboot-mysql&#8221;>GitHub&amp;lt;\/a>.&amp;lt;\/p> &amp;lt;p>Open POSTMAN and &amp;lt;strong>create&amp;lt;\/strong> a POST request to the URL &amp;lt;code>localhost:8090\/api\/users&amp;lt;\/code> with a random user object to be persisted in the DB:&amp;lt;\/p> &amp;lt;figure class=&#8221;kg-card kg-image-card kg-card-hascaption&#8221;>&amp;lt;img src=&#8221;https:\/\/assets.numericaideas.com\/2023\/07\/test-api-create-user.png&#8221; class=&#8221;kg-image&#8221; alt=&#8221;Dockerize Spring Boot and MySQL with Docker Compose&#8221; \/> &amp;lt;figcaption>Test API: create a user&amp;lt;\/figcaption> &amp;lt;p>&amp;lt;\/p>&amp;lt;\/figure> &amp;lt;p>Let&#8217;s &amp;lt;strong>list all users&amp;lt;\/strong> which includes the one we just created:&amp;lt;\/p> &amp;lt;figure class=&#8221;kg-card kg-image-card kg-card-hascaption&#8221;>&amp;lt;img src=&#8221;https:\/\/assets.numericaideas.com\/2023\/07\/test-api-list-users.png&#8221; class=&#8221;kg-image&#8221; alt=&#8221;Dockerize Spring Boot and MySQL with Docker Compose&#8221; \/> &amp;lt;figcaption>Test API: list all users&amp;lt;\/figcaption> &amp;lt;p>&amp;lt;\/p>&amp;lt;\/figure> &amp;lt;p>A &amp;lt;strong>ping&amp;lt;\/strong> endpoint is also available:&amp;lt;\/p> &amp;lt;figure class=&#8221;kg-card kg-image-card kg-card-hascaption&#8221;>&amp;lt;img src=&#8221;https:\/\/assets.numericaideas.com\/2023\/07\/test-api-ping.png&#8221; class=&#8221;kg-image&#8221; alt=&#8221;Dockerize Spring Boot and MySQL with Docker Compose&#8221; \/> &amp;lt;figcaption>Test API: ping endpoint&amp;lt;\/figcaption> &amp;lt;p>&amp;lt;\/p>&amp;lt;\/figure> &amp;lt;p>If you are interested in related content, take a look at the following which explains how to &amp;lt;a href=&#8221;https:\/\/blog.numericaideas.com\/quickly-dockerizing-nodejs&#8221;>Quickly Dockerizing NodeJS Application using docker init command&amp;lt;\/a>:&amp;lt;\/p> &amp;lt;figure class=&#8221;kg-card kg-bookmark-card&#8221;>&amp;lt;a class=&#8221;kg-bookmark-container&#8221; href=&#8221;https:\/\/blog.numericaideas.com\/quickly-dockerizing-nodejs&#8221;> &amp;lt;div class=&#8221;kg-bookmark-content&#8221;> &amp;lt;div class=&#8221;kg-bookmark-title&#8221;>Docker Init: Quickly Dockerizing NodeJS Application&amp;lt;\/div> &amp;lt;div class=&#8221;kg-bookmark-description&#8221;>The docker init command is a powerful tool that enables developers to generate Dockerfiles and Docker Compose files effortlessly.&amp;lt;\/div> &amp;lt;div class=&#8221;kg-bookmark-metadata&#8221;>&amp;lt;img class=&#8221;kg-bookmark-icon&#8221; src=&#8221;https:\/\/s3.amazonaws.com\/ni-ghost\/2021\/05\/logo_numerica_ideas-1.png&#8221; alt=&#8221;Dockerize Spring Boot and MySQL with Docker Compose&#8221; \/>&amp;lt;span class=&#8221;kg-bookmark-author&#8221;>Orleando Dassi&amp;lt;\/span>&amp;lt;span class=&#8221;kg-bookmark-publisher&#8221;>Docker Init: Quickly Dockerizing NodeJS Application&amp;lt;\/span>&amp;lt;\/div> &amp;lt;\/div> &amp;lt;div class=&#8221;kg-bookmark-thumbnail&#8221;>&amp;lt;img src=&#8221;https:\/\/assets.numericaideas.com\/2023\/08\/quickly-dockerizing-nodejs-application.png&#8221; alt=&#8221;Dockerize Spring Boot and MySQL with Docker Compose&#8221; \/>&amp;lt;\/div> &amp;lt;p>&amp;lt;\/p>&amp;lt;\/a>&amp;lt;\/figure> &amp;lt;p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014&amp;lt;\/p> &amp;lt;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.&amp;lt;\/p> &amp;lt;p>Does this speak to you? If &amp;lt;strong>YES&amp;lt;\/strong>, feel free to &amp;lt;a href=&#8221;https:\/\/discord.numericaideas.com\/&#8221; rel=&#8221;nofollow&#8221;>Join our Discord Server&amp;lt;\/a> to stay in touch with the community and be part of independently organized events.&amp;lt;\/p> &amp;lt;p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014&amp;lt;\/p> &amp;lt;h2 id=&#8221;conclusion&#8221;>Conclusion&amp;lt;\/h2> &amp;lt;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.&amp;lt;\/p> &amp;lt;p>Thanks for reading this article. Like, recommend, and share if you enjoyed it. Follow us on &amp;lt;a href=&#8221;https:\/\/www.facebook.com\/numericaideas&#8221; rel=&#8221;nofollow&#8221;>Facebook&amp;lt;\/a>, &amp;lt;a href=&#8221;https:\/\/twitter.com\/numericaideas&#8221; rel=&#8221;nofollow&#8221;>Twitter&amp;lt;\/a>, and &amp;lt;a href=&#8221;https:\/\/www.linkedin.com\/company\/numericaideas&#8221; rel=&#8221;nofollow&#8221;>LinkedIn&amp;lt;\/a> for more content.&amp;lt;\/p><\/iframe><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"docker-compose-spring-boot-and-mysql\">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&nbsp;<code>docker-compose.yml<\/code>&nbsp;in your project directory and add the following configuration:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">version: '3.7'\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: [\"CMD\", \"mysqladmin\" ,\"ping\", \"-h\", \"localhost\"]\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>Here&#8217;s what happens when Docker Compose processes these configurations: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This Docker Compose configuration defines two services:&nbsp;<code>app<\/code>&nbsp;for the&nbsp;<strong>NodeJS Application<\/strong>&nbsp;and&nbsp;<code>mysqldb<\/code>&nbsp;for the&nbsp;<strong>MySQL database<\/strong>.<\/li>\n\n\n\n<li>The&nbsp;<code>app<\/code>&nbsp;service builds the image based on the&nbsp;<a href=\"https:\/\/github.com\/numerica-ideas\/community\/blob\/master\/docker\/docker-compose-nodejs-mysql\/Dockerfile\" target=\"_blank\" rel=\"noreferrer noopener\">Dockerfile<\/a>&nbsp;in the project&#8217;s root directory.<\/li>\n\n\n\n<li>The&nbsp;<code>mysqldb<\/code>&nbsp;service uses the official&nbsp;<strong>MySQL<\/strong>&nbsp;image and sets the environment variables for the database configuration.<\/li>\n\n\n\n<li>The&nbsp;<code>depends_on<\/code>&nbsp;attribute ensures that the NodeJS application starts after the MySQL database to guarantee dependency ordering.<\/li>\n\n\n\n<li>Finally, the&nbsp;<code>healthcheck<\/code>&nbsp;makes sure the MySQL service is ready to accept connections before running the App.<\/li>\n<\/ul>\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 to the MySQL services&#8217; environment attributes so these are 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&nbsp;<strong>app<\/strong>&nbsp;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: It contains the <strong>DB Host<\/strong> which is addressable via the <strong>mysqldb<\/strong> service name since both services are in the same network. The DB name and port are included in this string too.<\/li>\n\n\n\n<li>SPRING_DATASOURCE_USERNAME: The username to access the DB with.<\/li>\n\n\n\n<li>SPRING_DATASOURCE_PASSWORD: The password to access the DB with.<\/li>\n<\/ul>\n\n\n\n<p>Spring Boot automatically assigns these variables to the related&nbsp;<strong>application.properties<\/strong>&nbsp;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>This means we don&#8217;t have to provide these manually in the&nbsp;<strong>application.properties<\/strong>&nbsp;file, so the App will be connected to the database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"run-the-dockerized-application\">Run the Dockerized Spring Boot Application With MySQL<\/h2>\n\n\n\n<p>To run the App via&nbsp;<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&nbsp;<strong>environment variables<\/strong>&nbsp;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&nbsp;<code>.env<\/code>&nbsp;file, feel free to create it from the&nbsp;<code><a href=\"https:\/\/github.com\/numerica-ideas\/community\/blob\/master\/docker\/docker-compose-springboot-mysql\/.env.sample\" target=\"_blank\" rel=\"noreferrer noopener\">.env.sample<\/a><\/code>&nbsp;file and put it close to the&nbsp;<code>docker-compose.yml<\/code>&nbsp;within the project. In case these files are in different locations, you must use the <strong>env_file<\/strong> field in the <strong>mysqldb<\/strong> service to specify the folder to access the .env file.<\/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, create the network, and start them all. 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&nbsp;<strong>Docker Desktop<\/strong>&nbsp;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\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.numericaideas.com\/2023\/07\/docker-desktop-running-containers.png\" alt=\"running-containers\"\/><figcaption class=\"wp-element-caption\">Running containers on Docker Desktop<\/figcaption><\/figure>\n\n\n\n<p>The complete source code of the project is available on&nbsp;<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&nbsp;<strong>create<\/strong>&nbsp;a POST request to the URL&nbsp;<code>localhost:8090\/api\/users<\/code>&nbsp;with a random user object to be persisted in the DB:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.numericaideas.com\/2023\/07\/test-api-create-user.png\" alt=\"create-user\"\/><figcaption class=\"wp-element-caption\">Test API: create a user<\/figcaption><\/figure>\n\n\n\n<p>Let&#8217;s&nbsp;<strong>list all users<\/strong>&nbsp;which includes the one we just created:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.numericaideas.com\/2023\/07\/test-api-list-users.png\" alt=\"list-users\"\/><figcaption class=\"wp-element-caption\">Test API: list all users<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Stop Docker Compose Services<\/h2>\n\n\n\n<p>To <strong>stop<\/strong> all the running containers, run:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">docker compose down<\/pre>\n\n\n\n<p>Here&#8217;s the exact command to <strong>stop and remove<\/strong> everything created by <strong>Docker Compose<\/strong>, talking about the <strong>containers<\/strong>, <strong>images<\/strong>, and <strong>networks<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">docker compose down --rmi all<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Other Docker Compose Examples<\/h2>\n\n\n\n<p>Do you want to apply the same with a Spring Boot Application? Read this article titled <a href=\"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\" target=\"_blank\" rel=\"noreferrer noopener\">Dockerize NodeJS and MySQL with Docker Compose<\/a>:<\/p>\n\n\n<div class=\"vlp-link-container vlp-layout-basic wp-block-visual-link-preview-link\"><a href=\"https:\/\/dassiorleando.com\/fr\/docker-compose-nodejs-mysql\/\" class=\"vlp-link\" title=\"Dockerize NodeJS and MySQL with Docker Compose\"><\/a><div class=\"vlp-layout-zone-side\"><div class=\"vlp-block-2 vlp-link-image\"><img decoding=\"async\" style=\"max-width: 150px;\" width=\"150\" height=\"84\" src=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL.png\" class=\"attachment-150x999 size-150x999\" alt=\"Dockerize NodeJS and MySQL with Docker Compose\" srcset=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL.png 1366w, https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL-300x169.png 300w, https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL-1024x576.png 1024w, https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL-768x432.png 768w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/div><\/div><div class=\"vlp-layout-zone-main\"><div class=\"vlp-block-0 vlp-link-title\">Dockerize NodeJS and MySQL with Docker Compose<\/div><div class=\"vlp-block-1 vlp-link-summary\">Let&#8217;s Dockerize a NodeJS Application with MySQL by leveraging the power of Docker Compose to achieve easy deployment and portability.<\/div><\/div><\/div>\n\n\n<p>If you are interested in related content, take a look at the following which explains how to&nbsp;<a href=\"https:\/\/numericaideas.com\/blog\/quickly-dockerizing-nodejs\" target=\"_blank\" rel=\"noreferrer noopener\">Quickly Dockerizing NodeJS Application using the Docker Init Command<\/a>:<\/p>\n\n\n<div class=\"vlp-link-container vlp-layout-basic wp-block-visual-link-preview-link\"><a href=\"https:\/\/numericaideas.com\/blog\/quickly-dockerizing-nodejs\/\" class=\"vlp-link\" title=\"Docker Init: Quickly Dockerizing NodeJS Application\" rel=\"nofollow\" target=\"_blank\"><\/a><div class=\"vlp-layout-zone-side\"><div class=\"vlp-block-2 vlp-link-image\"><img decoding=\"async\" src=\"https:\/\/assets.numericaideas.com\/2023\/08\/quickly-dockerizing-nodejs-min.png\" style=\"max-width: 150px; max-height: 150px\" \/><\/div><\/div><div class=\"vlp-layout-zone-main\"><div class=\"vlp-block-0 vlp-link-title\">Docker Init: Quickly Dockerizing NodeJS Application<\/div><div class=\"vlp-block-1 vlp-link-summary\">The docker init command is a powerful tool that enables developers to generate Dockerfiles and Docker Compose files effortlessly.<\/div><\/div><\/div>\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&nbsp;<strong>YES<\/strong>, feel free to&nbsp;<a href=\"https:\/\/discord.numericaideas.com\/\">Join our Discord Server<\/a>&nbsp;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\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>By following the steps outlined in this guide, we were able to package a NodeJS application and MySQL database into separate containers and deploy them as a cohesive application stack using Docker Compose. 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&nbsp;<a href=\"https:\/\/www.facebook.com\/numericaideas\">Facebook<\/a>,&nbsp;<a href=\"https:\/\/twitter.com\/numericaideas\">Twitter<\/a>, and&nbsp;<a href=\"https:\/\/www.linkedin.com\/company\/numericaideas\">LinkedIn<\/a>&nbsp;for more content.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;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.<\/p>","protected":false},"author":2,"featured_media":18687,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64,66],"tags":[55,30,56,58],"class_list":["post-17176","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-full-stack","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<\/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\" \/>\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-07-25T01:46:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-07T03:36:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min.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=\"13 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-2\/\"},\"author\":{\"name\":\"Orl\u00e9ando Dassi\",\"@id\":\"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e\"},\"headline\":\"Dockerize Spring Boot and MySQL with Docker Compose\",\"datePublished\":\"2023-07-25T01:46:14+00:00\",\"dateModified\":\"2025-01-07T03:36:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/dassiorleando.com\/docker-compose-springboot-mysql-2\/\"},\"wordCount\":3429,\"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\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min.png\",\"keywords\":[\"Docker\",\"JAVA\",\"Solutions Architecture\",\"Spring Boot\"],\"articleSection\":[\"DevOps\",\"Full Stack\"],\"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-2\/\",\"url\":\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/\",\"name\":\"Dockerize Spring Boot and MySQL with Docker Compose\",\"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\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min.png\",\"datePublished\":\"2023-07-25T01:46:14+00:00\",\"dateModified\":\"2025-01-07T03:36:15+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\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min.png\",\"contentUrl\":\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min.png\",\"width\":1366,\"height\":768,\"caption\":\"Dockerize Spring Boot and MySQL with Docker Compose\"},{\"@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","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","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-07-25T01:46:14+00:00","article_modified_time":"2025-01-07T03:36:15+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min.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":"13 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-2\/"},"author":{"name":"Orl\u00e9ando Dassi","@id":"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e"},"headline":"Dockerize Spring Boot and MySQL with Docker Compose","datePublished":"2023-07-25T01:46:14+00:00","dateModified":"2025-01-07T03:36:15+00:00","mainEntityOfPage":{"@id":"https:\/\/dassiorleando.com\/docker-compose-springboot-mysql-2\/"},"wordCount":3429,"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\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min.png","keywords":["Docker","JAVA","Solutions Architecture","Spring Boot"],"articleSection":["DevOps","Full Stack"],"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-2\/","url":"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/","name":"Dockerize Spring Boot and MySQL with Docker Compose","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\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min.png","datePublished":"2023-07-25T01:46:14+00:00","dateModified":"2025-01-07T03:36:15+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\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min.png","contentUrl":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min.png","width":1366,"height":768,"caption":"Dockerize Spring Boot and MySQL with Docker Compose"},{"@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\/17176","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=17176"}],"version-history":[{"count":1,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/posts\/17176\/revisions"}],"predecessor-version":[{"id":21665,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/posts\/17176\/revisions\/21665"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/media\/18687"}],"wp:attachment":[{"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/media?parent=17176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/categories?post=17176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/tags?post=17176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}