{"id":91177,"date":"2020-06-24T11:00:00","date_gmt":"2020-06-24T08:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=91177"},"modified":"2020-06-18T11:57:28","modified_gmt":"2020-06-18T08:57:28","slug":"deploying-multiple-spring-boot-microservices-to-docker","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/","title":{"rendered":"Deploying Multiple Spring Boot Microservices to Docker"},"content":{"rendered":"<p>Welcome readers, in this tutorial, we will show how to deploy multiple Spring Boot Microservices on Docker.<\/p>\n<h2 class=\"wp-block-heading\">1. Introduction<\/h2>\n<p>Before starting the tutorial, we will make an introduction to Spring Boot and Docker.<\/p>\n<h3 class=\"wp-block-heading\">1.1 Spring Boot introduction<\/h3>\n<ul class=\"wp-block-list\">\n<li>Spring boot is a module that provides rapid application development feature to the spring framework including <strong>auto-configuration<\/strong>, <strong>standalone-code<\/strong>, and <strong>production-ready<\/strong> code<\/li>\n<li>It creates applications that are packaged as <em>jar<\/em> and are directly started using embedded servlet container (such as Tomcat, Jetty or Undertow). Thus, no need to deploy the war files<\/li>\n<li>It simplifies the maven configuration by providing the starter template and helps to resolve the dependency conflicts. It automatically identifies the required dependencies and imports them in the application<\/li>\n<li>It helps in removing the boilerplate code, extra annotations, and XML configurations<\/li>\n<li>It provides a powerful batch processing and manages the rest endpoints<\/li>\n<li>It provides an efficient JPA<em>-starter library<\/em> to effectively connect the application with the relational databases<\/li>\n<li>It offers a Microservice architecture and cloud configuration that manages all the application related configuration properties in a centralized manner<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">1.2 Docker introduction<\/h3>\n<p>In the present world, <strong>Docker<\/strong> is an important term,<\/p>\n<ul class=\"wp-block-list\">\n<li>Often used in CI\/CD platform that packages and runs the application with its dependencies inside a container<\/li>\n<li>Is a standard for Linux Containers<\/li>\n<li>A <em>Container<\/em> is a runtime that runs under any Linux kernel and provides a private machine-like space under Linux<\/li>\n<\/ul>\n<h4 class=\"wp-block-heading\">1.2.1 Docker Terminology<\/h4>\n<ul class=\"wp-block-list\">\n<li><strong>Image<\/strong>: Representation of Docker container i.e. a JAR or WAR file in Java<\/li>\n<li><strong>Container<\/strong>: Runtime of Docker i.e. a deployed and running Docker image. For example, an executable Spring Boot jar<\/li>\n<li><strong>Engine<\/strong>: The code that manages, creates and runs the Docker containers<\/li>\n<li><strong>Hub<\/strong>: A public developers registry to distribute their code<\/li>\n<li><strong>Repository<\/strong>: A collection of Docker related images i.e. different versions of the same application<\/li>\n<\/ul>\n<h4 class=\"wp-block-heading\">1.2.2 Docker Command Basics<\/h4>\n<p>Here\u2019s an example command.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"817\" height=\"286\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/Docker-command-basics-img1-1.jpg\" alt=\"Spring Boot Microservices Docker\" class=\"wp-image-91179\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/Docker-command-basics-img1-1.jpg 817w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/Docker-command-basics-img1-1-300x105.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/Docker-command-basics-img1-1-768x269.jpg 768w\" sizes=\"(max-width: 817px) 100vw, 817px\" \/><figcaption>Fig. 1: Basic structure<\/figcaption><\/figure>\n<\/div>\n<h4>1.2.3 Need for using Docker<\/h4>\n<ul>\n<li>For environment replication, while the code runs locally on the machine<\/li>\n<li>For numerous deployment phases i.e. Dev\/Test\/QA<\/li>\n<li>For version control and distributing the application\u2019s OS within a team<\/li>\n<\/ul>\n<h4>1.2.4 Setting up Docker<\/h4>\n<p>If someone needs to go through the Docker installation, please watch <a href=\"https:\/\/www.youtube.com\/watch?v=R-ZMkGvh-9Y\" target=\"_blank\" rel=\"noopener noreferrer\">this<\/a> video.<\/p>\n<p>To start with this tutorial, we are hoping that users at present know the basis of a Spring boot application and have the Docker environment installed on a Windows operating system.<\/p>\n<h2>2. Deploying Multiple Spring Boot Microservices to Docker<\/h2>\n<p>In this tutorial, we will use the existing microservices implemented under the tutorial present at this <a href=\"https:\/\/examples.javacodegeeks.com\/spring-cloud-zipkin-and-sleuth-example\/\" target=\"_blank\" rel=\"noopener noreferrer\">javacodegeek<\/a> tutorial. Since both the microservices are the same and have a different port number so we will point out the required differences to be made. Or, readers have the easy option to download the source code from the <a href=\"#projectDownload\">project download<\/a> section. Let us start building our microservices!<\/p>\n<h3>2.1 Maven Dependency<\/h3>\n<p>In the microservices <code>pom.xml<\/code> file we will remove the dependencies like &#8211; <code> spring-cloud-starter-sleuth<\/code>, <code> spring-cloud-starter-sleuth<\/code> and the following dependency to the build section so that during the project packaging all the required jars are available to the microservice. This is an essential step once the application is deployed on the Docker environment.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>pom.xml<\/em><\/span><\/p>\n<div>\n<div id=\"highlighter_159708\" class=\"syntaxhighlighter  xml\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml comments\">&lt;!-- To make spring boot as a fat jar so that all required jar files and <\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"xml spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"xml comments\">main file is added for running the code from Docker. --&gt;<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">plugins<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"xml spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">plugin<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"xml spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">groupId<\/code><code class=\"xml plain\">&gt;org.springframework.boot&lt;\/<\/code><code class=\"xml keyword\">groupId<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"xml spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">artifactId<\/code><code class=\"xml plain\">&gt;spring-boot-maven-plugin&lt;\/<\/code><code class=\"xml keyword\">artifactId<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"xml spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"xml plain\">&lt;\/<\/code><code class=\"xml keyword\">plugin<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"xml plain\">&lt;\/<\/code><code class=\"xml keyword\">plugins<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>2.2 Changing the RestTemplate URL in Microservice1<\/h3>\n<p>As these microservices will be deployed on two different docker containers so for inter-communication from Microservice1 to Microservice2, we\u2019ll make a quick change in the RestTemplate URL. Head over to the Microservice1 controller class and replace the existing URL on line #29 with the one given below.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline;\"><em>Microservice1 Controller class<\/em><\/span><\/p>\n<div>\n<div id=\"highlighter_766103\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java keyword\">final<\/code> <code class=\"java plain\">String microservice2Url = <\/code><code class=\"java string\">\"<a href=\"http:\/\/microservice2:10092\/microservice2\">http:\/\/microservice2:10092\/microservice2<\/a>\"<\/code><code class=\"java plain\">;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>2.3 Adding the Dockerfile<\/h3>\n<p>This is an important part where we will add the <code>Dockerfile<\/code> to the project\u2019s root folder. This is required so that we can make a Docker image for our microservices which will be used later to deploy on the Docker container.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Dockerfile for Microservice1<\/em><\/span><\/p>\n<div>\n<div id=\"highlighter_38414\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">From openjdk:8<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"plain plain\">copy .\/target\/Microservice1.jar Microservice1.jar<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"plain plain\">CMD [\"java\",\"-jar\",\"Microservice1.jar\"]<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Similarly, we will create a <code>Dockerfile<\/code> for Microservice2.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Dockerfile for Microservice2<\/em><\/span><\/p>\n<div>\n<div id=\"highlighter_281857\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">From openjdk:8<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"plain plain\">copy .\/target\/Microservice2.jar Microservice2.jar<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"plain plain\">CMD [\"java\",\"-jar\",\"Microservice2.jar\"]<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>3. Docker Actions<\/h2>\n<p>Open the command prompt terminal and let us execute the below Docker commands.<\/p>\n<h3>3.1 Creating a Docker image for Microservice1<\/h3>\n<p>To create a Docker image for Microservice1, navigate to the project folder. Once there hit the following command to successfully create an image as shown in Fig. 2.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Docker Image build command<\/em><\/span><\/p>\n<div>\n<div id=\"highlighter_728701\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">## Building docker image for microservice1<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"plain plain\">docker image build -t microservice1 .<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>If everything goes well, the following output image will be shown.[ulp id=&#8217;6PVIvOz3kDbYmNRn&#8217;]<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"818\" height=\"312\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img1.jpg\" alt=\"Spring Boot Microservices Docker\" class=\"wp-image-91181\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img1.jpg 818w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img1-300x114.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img1-768x293.jpg 768w\" sizes=\"(max-width: 818px) 100vw, 818px\" \/><figcaption>Fig. 2: Creating a Docker image for microservice1<\/figcaption><\/figure>\n<\/div>\n<h3>3.2 Creating Docker images for Microservice2<\/h3>\n<p>To create a Docker image for Microservice2, navigate to the project folder. Once there hit the following command to successfully create an image as shown in Fig. 3.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Docker Image build command<\/em><\/span><\/p>\n<div>\n<div id=\"highlighter_571797\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">## Building docker image for microservice2<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"plain plain\">docker image build -t microservice2 .<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>If everything goes well, the following output image will be shown.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"818\" height=\"171\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img2.jpg\" alt=\"Spring Boot Microservices Docker\" class=\"wp-image-91182\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img2.jpg 818w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img2-300x63.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img2-768x161.jpg 768w\" sizes=\"(max-width: 818px) 100vw, 818px\" \/><figcaption>Fig. 3: Creating a docker image for microservice2<\/figcaption><\/figure>\n<\/div>\n<h3>3.3 Creating Docker Bridge network<\/h3>\n<p>To support the <em>inter-communication<\/em> between two different docker containers we\u2019ll need to create a new <strong>bridge-type docker network<\/strong>. If the developer needs to understand the Docker network they can refer to the tutorial available at this <a href=\"https:\/\/examples.javacodegeeks.com\/docker-machine-with-bridged-network-adapter-example\/\" target=\"_blank\" rel=\"noopener noreferrer\">javacodegeek<\/a> link.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Creating a new Docker network<\/em><\/span><\/p>\n<div>\n<div id=\"highlighter_323766\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">## Creating a bridge docker network for inter-networking communication between the two microservices<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"plain plain\">## Use \"docker network ls\" to verify that the new network is created successfully<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"plain plain\">docker network create microservice1-microservice2<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>If everything goes well, the following output image will be shown. Readers can also use the <code>docker inspect \u2026\u2026<\/code> to verify that newly created network.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"818\" height=\"43\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img3.jpg\" alt=\"\" class=\"wp-image-91183\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img3.jpg 818w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img3-300x16.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img3-768x40.jpg 768w\" sizes=\"(max-width: 818px) 100vw, 818px\" \/><figcaption>Fig. 4: Creating a new docker network<\/figcaption><\/figure>\n<\/div>\n<h3>3.4 Starting the Docker containers<\/h3>\n<p>In this step, we will start the Docker containers (for the docker images created above) on the new bridge network (i.e. <code>microservice1-microservice2<\/code>).<\/p>\n<p><span style=\"text-decoration: underline\"><em>Starting Docker containers<\/em><\/span><\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">## Starting docker container on the bridge network created\n### Running the microservice1 on a docker container and exposing port 10091 as\n### spring boot application is running on the port number- 10091\ndocker container run --network microservice1-microservice2 --name microservice1 -p 10091:10091 -d microservice1\n\n### Running the microservice2 on a docker container and exposing port 10092 as\n### spring boot application is running on the port number- 10092\ndocker container run --network microservice1-microservice2 --name microservice2 -p 10092:10092 -d microservice2\n<\/pre>\n<p>If everything goes well, developers can use the <code>docker ps -a<\/code> to verify that both the docker containers are successfully started.<\/p>\n<h2>4. Project Demo<\/h2>\n<p>Once the microservices are successfully started on the Docker network, developers need to open the browser of their choice and hit the following application URL.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Application URL<\/em><\/span><\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">http:\/\/localhost:10091\/microservice1\n<\/pre>\n<p>Once the hit this tutorial, the request will go to the HTTP GET method of microservice1 controller which in turn will forward this request to the HTTP GET method of microservice2 controller. This request flow implies that the request coming to microservice1 is dependent on microservice2 which in turn is responsible to provide a successful response or an error in case any exception occurs at the microservice2 during the request processing. If everything goes well, the below response will be shown to the user.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"467\" height=\"102\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img5.jpg\" alt=\"\" class=\"wp-image-91184\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img5.jpg 467w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/multiple-microservice-docker-networking-img5-300x66.jpg 300w\" sizes=\"(max-width: 467px) 100vw, 467px\" \/><figcaption>Fig. 5: Welcome message<\/figcaption><\/figure>\n<\/div>\n<p>That is all for this tutorial and I hope the article served you whatever you were looking for. In case the readers do not get a response they will hit the <code>docker logs &lt;container_id&gt;<\/code> command on the docker terminate to keep an eye on the container logs. Happy Learning and do not forget to share!<\/p>\n<h2>5. Summary<\/h2>\n<p>In the above sections, we learned the following:<\/p>\n<ul>\n<li>Introduction to Spring Boot and Docker<\/li>\n<li>Simple Spring boot application set up and deploy on Docker containers<\/li>\n<\/ul>\n<p>As the clarity of some demo images is blurry due to the size limitations, so readers can download the high-resolution images from the download section. Developers can download the sample application from the <a href=\"#projectDownload\">Download<\/a> section.<\/p>\n<h2><a name=\"projectDownload\"><\/a>6. Download the Project<\/h2>\n<p>This was a tutorial of Deploying Multiple Spring Boot Microservices to Docker.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>You can download the full source code of this example here: <strong><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/Deploying-Multiple-Spring-Boot-Microservices-to-Docker.zip\" target=\"_blank\" rel=\"noopener noreferrer\">Deploying Multiple Spring Boot Microservices to Docker<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Welcome readers, in this tutorial, we will show how to deploy multiple Spring Boot Microservices on Docker. 1. Introduction Before starting the tutorial, we will make an introduction to Spring Boot and Docker. 1.1 Spring Boot introduction Spring boot is a module that provides rapid application development feature to the spring framework including auto-configuration, standalone-code, &hellip;<\/p>\n","protected":false},"author":119,"featured_media":31013,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1354],"tags":[1276,1759,474,1386,1675],"class_list":["post-91177","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker","tag-docker","tag-microservices","tag-rest-2","tag-spring-boot","tag-spring-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Deploying Multiple Spring Boot Microservices to Docker - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Welcome readers, in this tutorial, we will show how to deploy multiple Spring Boot Microservices on Docker. 1. Introduction Before starting the tutorial,\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deploying Multiple Spring Boot Microservices to Docker - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Welcome readers, in this tutorial, we will show how to deploy multiple Spring Boot Microservices on Docker. 1. Introduction Before starting the tutorial,\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-24T08:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/\"},\"author\":{\"name\":\"Yatin\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\"},\"headline\":\"Deploying Multiple Spring Boot Microservices to Docker\",\"datePublished\":\"2020-06-24T08:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/\"},\"wordCount\":1148,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg\",\"keywords\":[\"docker\",\"Microservices\",\"REST\",\"spring boot\",\"spring tutorial\"],\"articleSection\":[\"Docker\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/\",\"name\":\"Deploying Multiple Spring Boot Microservices to Docker - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg\",\"datePublished\":\"2020-06-24T08:00:00+00:00\",\"description\":\"Welcome readers, in this tutorial, we will show how to deploy multiple Spring Boot Microservices on Docker. 1. Introduction Before starting the tutorial,\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DevOps\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/devops\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Docker\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/devops\/docker\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Deploying Multiple Spring Boot Microservices to Docker\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\",\"name\":\"Yatin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"caption\":\"Yatin\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Deploying Multiple Spring Boot Microservices to Docker - Java Code Geeks","description":"Welcome readers, in this tutorial, we will show how to deploy multiple Spring Boot Microservices on Docker. 1. Introduction Before starting the tutorial,","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:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/","og_locale":"en_US","og_type":"article","og_title":"Deploying Multiple Spring Boot Microservices to Docker - Java Code Geeks","og_description":"Welcome readers, in this tutorial, we will show how to deploy multiple Spring Boot Microservices on Docker. 1. Introduction Before starting the tutorial,","og_url":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-06-24T08:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg","type":"image\/jpeg"}],"author":"Yatin","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/"},"author":{"name":"Yatin","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13"},"headline":"Deploying Multiple Spring Boot Microservices to Docker","datePublished":"2020-06-24T08:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/"},"wordCount":1148,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg","keywords":["docker","Microservices","REST","spring boot","spring tutorial"],"articleSection":["Docker"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/","url":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/","name":"Deploying Multiple Spring Boot Microservices to Docker - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg","datePublished":"2020-06-24T08:00:00+00:00","description":"Welcome readers, in this tutorial, we will show how to deploy multiple Spring Boot Microservices on Docker. 1. Introduction Before starting the tutorial,","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/deploying-multiple-spring-boot-microservices-to-docker\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"DevOps","item":"https:\/\/examples.javacodegeeks.com\/category\/devops\/"},{"@type":"ListItem","position":3,"name":"Docker","item":"https:\/\/examples.javacodegeeks.com\/category\/devops\/docker\/"},{"@type":"ListItem","position":4,"name":"Deploying Multiple Spring Boot Microservices to Docker"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13","name":"Yatin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","caption":"Yatin"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/91177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=91177"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/91177\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/31013"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=91177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=91177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=91177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}