{"id":20673,"date":"2024-01-31T05:14:19","date_gmt":"2024-01-31T05:14:19","guid":{"rendered":"https:\/\/numericaideas.com\/?p=20673"},"modified":"2025-01-07T04:28:05","modified_gmt":"2025-01-07T03:28:05","slug":"docker-compose-nodejs-mysql","status":"publish","type":"post","link":"https:\/\/dassiorleando.com\/fr\/docker-compose-nodejs-mysql\/","title":{"rendered":"Dockerize NodeJS and MySQL with Docker Compose"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"introduction\">Introduction<\/h2>\n\n\n\n<p><strong>Docker<\/strong> has transformed the landscape of application deployment by empowering developers to encapsulate applications along with their dependencies into portable containers. In this article, we&#8217;ll explore how to dockerize a <strong>NodeJS<\/strong> application with <strong>MySQL<\/strong>, leveraging the power of <strong>Docker<\/strong> and <strong>Docker Compose<\/strong>. Containerizing your Node.js application offers seamless deployment, enhanced portability, scalability, and version control benefits.<\/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>Docker Compose 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 on your machine:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Docker installed and running on your machine, <a href=\"https:\/\/docs.docker.com\/get-docker\/\" rel=\"nofollow\">this guide<\/a> can help.<\/li>\n\n\n\n<li>NodeJS, any of the recent versions will do.<\/li>\n\n\n\n<li>NPM normally comes with the installation of NodeJS.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"create-a-spring-boot-application\">Create a NodeJS Application<\/h2>\n\n\n\n<p>Before proceeding, let&#8217;s create a basic <strong>NodeJS<\/strong> App with the latest LTS release at the time of writing, which is version <strong>v18.x.x<\/strong>.<\/p>\n\n\n\n<p>This article is about Docker Compose, so we suggest you follow along using our sample project available on <a href=\"https:\/\/github.com\/numerica-ideas\/community\/tree\/master\/docker\/docker-compose-nodejs-mysql\">GitHub<\/a>.<\/p>\n\n\n\n<p>You can quickly determine the following dependencies that come packaged in the project:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Express<\/strong>: The web framework to easily build RESTful APIs.<\/li>\n\n\n\n<li><strong>Sequelize<\/strong>: The Object Relational Mapping (ORM) performs database queries easily.<\/li>\n\n\n\n<li><strong>MySQL2<\/strong>: The MySQL driver used by Sequelize to interact with a MySQL database.<\/li>\n<\/ul>\n\n\n\n<p>The <strong><a href=\"https:\/\/github.com\/numerica-ideas\/community\/blob\/master\/docker\/docker-compose-nodejs-mysql\/db.config.js\" target=\"_blank\" rel=\"noreferrer noopener\">db.config.js<\/a><\/strong> file holds the database configurations the project used via the Sequelize package, here&#8217;s what it looks like:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\/**\n * Database configuration.\n *\/\nmodule.exports = {\n    DIALECT: 'mysql',\n    HOST: process.env.DB_HOST,\n    PORT: process.env.DB_PORT,\n    DB: process.env.DB_NAME,\n    USERNAME: process.env.DB_USERNAME,\n    PASSWORD: process.env.DB_PASSWORD,\n};<\/pre>\n\n\n\n<p>For our demo, the port in use is <strong>3000<\/strong> and we have implemented the CRUD operations for a basic <strong>User<\/strong> model 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 <strong>NodeJS<\/strong> project too.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"create-docker-image-for-spring-boot-application\">Create Docker Image for NodeJS Application<\/h2>\n\n\n\n<p>The <code><a href=\"https:\/\/github.com\/numerica-ideas\/community\/blob\/master\/docker\/docker-compose-nodejs-mysql\/Dockerfile\" target=\"_blank\" rel=\"noreferrer noopener\">Dockerfile<\/a><\/code> should be provided to build an image of the NodeJS Application, it contains the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\"># Use a base image with NodeJS 18\nFROM node:18\n# Install all the dependencies in the container using the package.json file\nCOPY package.json .\nRUN npm install\n# Copy the remaining project files to the container\nCOPY . .\n# Expose the application port\nEXPOSE 3000\n# Run the App\nCMD npm start<\/pre>\n\n\n\n<p>It&#8217;s straightforward, the <code>Dockerfile<\/code> uses an image based on <strong>NodeJS 18<\/strong>, installs the dependencies into the container, copies the project files, exposes the <strong>port<\/strong> the App is running on, and then provides the <strong>CMD (npm start)<\/strong> which is the command to run when the container starts.<\/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 size-large\"><img decoding=\"async\" src=\"https:\/\/numericaideas.com\/wp-content\/uploads\/2024\/01\/docker-compose-nodejs-mysql-image-1300x762.png\" alt=\"Dockerfile for NodeJS Application\" class=\"wp-image-20692\"\/><figcaption class=\"wp-element-caption\">Build NodeJS Docker image<\/figcaption><\/figure>\n\n\n\n<p>As of now, we have the <strong>NodeJS App image<\/strong> and we&#8217;ll use the <a href=\"https:\/\/hub.docker.com\/_\/mysql\" target=\"_blank\" rel=\"noreferrer noopener\">official MySQL Docker image<\/a> available in the Docker Hub. 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 NodeJS and MySQL<\/h2>\n\n\n\n<p>Docker Compose simplifies the orchestration of multi-container applications. To get started, create a file named <code>docker-compose.yml<\/code> in your project directory and incorporate the provided 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      - 3000:3000\n    depends_on:\n      mysqldb:\n        condition: service_healthy\n    environment:\n      - DB_HOST=mysqldb\n      - DB_PORT=3306\n      - DB_NAME=${MYSQL_DATABASE}\n      - DB_USERNAME=root\n      - DB_PASSWORD=${MYSQL_PASSWORD}\n    networks:\n      - nodejs-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      - nodejs-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  nodejs-mysql-network:\n    name: nodejs-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>DB_HOST: Since both services are in the same network, the database instance is addressable via the <strong>mysqldb<\/strong> service name.<\/li>\n\n\n\n<li>DB_PORT: The database port.<\/li>\n\n\n\n<li>DB_NAME: the database name.<\/li>\n\n\n\n<li>DB_USERNAME: The username to access the DB with.<\/li>\n\n\n\n<li>DB_PASSWORD: The password to access the DB with.<\/li>\n<\/ul>\n\n\n\n<p>NodeJS automatically picks them up and makes these database details available in the <strong>process.env<\/strong> object used by the <a href=\"https:\/\/github.com\/numerica-ideas\/community\/blob\/master\/docker\/docker-compose-nodejs-mysql\/db.config.js\" target=\"_blank\" rel=\"noreferrer noopener\">db.config.js<\/a> file that we clarified on the top.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"run-the-dockerized-application\">Run the Dockerized NodeJS Application With MySQL<\/h2>\n\n\n\n<p>To run the App via&nbsp;<strong>Docker Compose<\/strong>, open a terminal, jump 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-nodejs-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;file 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 NodeJS App 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 size-large\"><img decoding=\"async\" src=\"https:\/\/numericaideas.com\/wp-content\/uploads\/2024\/01\/docker-compose-nodejs-mysql-running-1268x800.png\" alt=\"Docker Compose NodeJS MySQL Running\" class=\"wp-image-20700\"\/><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-nodejs-mysql\" target=\"_blank\" rel=\"noreferrer noopener\">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:3000\/users<\/code>&nbsp;with a random user object to be persisted in the DB:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/numericaideas.com\/wp-content\/uploads\/2024\/01\/docker-compose-nodejs-mysql-create-user-1300x581.png\" alt=\"Docker Compose NodeJS MySQL: Create User API\" class=\"wp-image-20703\"\/><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 size-large\"><img decoding=\"async\" src=\"https:\/\/numericaideas.com\/wp-content\/uploads\/2024\/01\/docker-compose-nodejs-mysql-list-users-1300x557.png\" alt=\"Docker Compose NodeJS MySQL: List Users API\" class=\"wp-image-20705\"\/><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>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 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>Do you want to apply the same with a Spring Boot Application? Read this article titled <a href=\"https:\/\/numericaideas.com\/blog\/docker-compose-springboot-mysql\/\" target=\"_blank\" rel=\"noreferrer noopener\">Dockerize Spring Boot 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-springboot-mysql-2\/\" class=\"vlp-link\" title=\"Dockerize Spring Boot 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\/2023\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min.png\" class=\"attachment-150x999 size-150x999\" alt=\"Dockerize Spring Boot and MySQL with Docker Compose\" srcset=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min.png 1366w, https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min-300x169.png 300w, https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min-1024x576.png 1024w, https:\/\/dassiorleando.com\/wp-content\/uploads\/2023\/07\/Dockerize-Spring-Boot-Application-with-MySQL-1-min-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 Spring Boot and MySQL with Docker Compose<\/div><div class=\"vlp-block-1 vlp-link-summary\">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.<\/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 Dockerize a NodeJS Application with MySQL by leveraging the power of Docker Compose to achieve easy deployment and portability.<\/p>","protected":false},"author":2,"featured_media":20822,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61,64],"tags":[55,38,56],"class_list":["post-20673","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-backend","category-devops","tag-docker","tag-nodejs","tag-solutions-architecture"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Dockerize NodeJS and MySQL with Docker Compose<\/title>\n<meta name=\"description\" content=\"Let&#039;s Dockerize a NodeJS Application with MySQL by leveraging the power of Docker Compose to achieve easy deployment and portability.\" \/>\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-nodejs-mysql\/\" \/>\n<meta property=\"og:locale\" content=\"fr_CA\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dockerize NodeJS and MySQL with Docker Compose\" \/>\n<meta property=\"og:description\" content=\"Let&#039;s Dockerize a NodeJS Application with MySQL by leveraging the power of Docker Compose to achieve easy deployment and portability.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/\" \/>\n<meta property=\"og:site_name\" content=\"Orleando Dassi\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-31T05:14:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-07T03:28:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-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=\"12 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-nodejs-mysql\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/dassiorleando.com\/docker-compose-nodejs-mysql\/\"},\"author\":{\"name\":\"Orl\u00e9ando Dassi\",\"@id\":\"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e\"},\"headline\":\"Dockerize NodeJS and MySQL with Docker Compose\",\"datePublished\":\"2024-01-31T05:14:19+00:00\",\"dateModified\":\"2025-01-07T03:28:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/dassiorleando.com\/docker-compose-nodejs-mysql\/\"},\"wordCount\":3250,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e\"},\"image\":{\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL.png\",\"keywords\":[\"Docker\",\"NodeJS\",\"Solutions Architecture\"],\"articleSection\":[\"Backend\",\"DevOps\"],\"inLanguage\":\"fr-CA\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dassiorleando.com\/docker-compose-nodejs-mysql\/\",\"url\":\"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/\",\"name\":\"Dockerize NodeJS and MySQL with Docker Compose\",\"isPartOf\":{\"@id\":\"https:\/\/dassiorleando.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL.png\",\"datePublished\":\"2024-01-31T05:14:19+00:00\",\"dateModified\":\"2025-01-07T03:28:05+00:00\",\"description\":\"Let's Dockerize a NodeJS Application with MySQL by leveraging the power of Docker Compose to achieve easy deployment and portability.\",\"breadcrumb\":{\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#breadcrumb\"},\"inLanguage\":\"fr-CA\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-CA\",\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#primaryimage\",\"url\":\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL.png\",\"contentUrl\":\"https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL.png\",\"width\":1366,\"height\":768,\"caption\":\"Dockerize NodeJS and MySQL with Docker Compose\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dassiorleando.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dockerize NodeJS 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 NodeJS and MySQL with Docker Compose","description":"Let's Dockerize a NodeJS Application with MySQL by leveraging the power of Docker Compose to achieve easy deployment and portability.","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-nodejs-mysql\/","og_locale":"fr_CA","og_type":"article","og_title":"Dockerize NodeJS and MySQL with Docker Compose","og_description":"Let's Dockerize a NodeJS Application with MySQL by leveraging the power of Docker Compose to achieve easy deployment and portability.","og_url":"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/","og_site_name":"Orleando Dassi","article_published_time":"2024-01-31T05:14:19+00:00","article_modified_time":"2025-01-07T03:28:05+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-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":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#article","isPartOf":{"@id":"https:\/\/dassiorleando.com\/docker-compose-nodejs-mysql\/"},"author":{"name":"Orl\u00e9ando Dassi","@id":"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e"},"headline":"Dockerize NodeJS and MySQL with Docker Compose","datePublished":"2024-01-31T05:14:19+00:00","dateModified":"2025-01-07T03:28:05+00:00","mainEntityOfPage":{"@id":"https:\/\/dassiorleando.com\/docker-compose-nodejs-mysql\/"},"wordCount":3250,"commentCount":0,"publisher":{"@id":"https:\/\/dassiorleando.com\/#\/schema\/person\/4862911e9cf93aa12f17875f7b7b1c5e"},"image":{"@id":"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL.png","keywords":["Docker","NodeJS","Solutions Architecture"],"articleSection":["Backend","DevOps"],"inLanguage":"fr-CA","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dassiorleando.com\/docker-compose-nodejs-mysql\/","url":"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/","name":"Dockerize NodeJS and MySQL with Docker Compose","isPartOf":{"@id":"https:\/\/dassiorleando.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#primaryimage"},"image":{"@id":"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL.png","datePublished":"2024-01-31T05:14:19+00:00","dateModified":"2025-01-07T03:28:05+00:00","description":"Let's Dockerize a NodeJS Application with MySQL by leveraging the power of Docker Compose to achieve easy deployment and portability.","breadcrumb":{"@id":"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#breadcrumb"},"inLanguage":"fr-CA","potentialAction":[{"@type":"ReadAction","target":["https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/"]}]},{"@type":"ImageObject","inLanguage":"fr-CA","@id":"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#primaryimage","url":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL.png","contentUrl":"https:\/\/dassiorleando.com\/wp-content\/uploads\/2024\/01\/Dockerize-NodeJS-Application-with-MySQL.png","width":1366,"height":768,"caption":"Dockerize NodeJS and MySQL with Docker Compose"},{"@type":"BreadcrumbList","@id":"https:\/\/numericaideas.com\/blog\/docker-compose-nodejs-mysql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dassiorleando.com\/"},{"@type":"ListItem","position":2,"name":"Dockerize NodeJS 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\/20673","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=20673"}],"version-history":[{"count":1,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/posts\/20673\/revisions"}],"predecessor-version":[{"id":21647,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/posts\/20673\/revisions\/21647"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/media\/20822"}],"wp:attachment":[{"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/media?parent=20673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/categories?post=20673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dassiorleando.com\/fr\/wp-json\/wp\/v2\/tags?post=20673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}