Search Tutorials

Deploying Multiple Spring Boot Microservices using Docker Compose | JavaInUse

Deploying Multiple Spring Boot Microservices using Docker Compose

In a previous docker tutorial we saw how to deploy multiple Spring Boot Microservices to Docker Container using docker networking. But previously we had to do the following steps manually-
  • Create custom docker network named consumer-producer network
  • Start Container named producer using image employee-producer and the custom network consumer-producer
  • Start Container named consumer using image employee-consumer and the custom network consumer-producer
The above steps can be automated using docker compose.
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services. Then, with a single command, you create and start all the services from your configuration.
Using docker-compose we will be creating the custom network named consumer-producer and then starting the containers employee-producer and employee consumer.
Using Compose is basically a three-step process-
  • Define your app's environment with a Dockerfile so it can be reproduced anywhere.
  • Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
  • Run docker-compose up and Compose starts and runs your entire app.

Docker Tutorial - Table Of Contents

Docker Deploying Spring Based WAR Application to Docker Deploying Spring Based JAR Application to Docker Deploying Multiple Spring Boot Microservices using Docker Networking Deploying Multiple Spring Boot Microservices using Docker Compose Deploying Spring Boot + MYSQL Application to Docker Publishing Docker Image to DockerHub Deploy Docker Swarm services using Play With Docker Deploy Docker Swarm services using Docker Stack Deploy Docker Swarm services to multiple AWS EC2 instances Docker Cheat Sheet


This tutorial is explained in the below Youtube Video.

Lets Begin-

The employee-producer and employee consumer projects will be exactly similar to what we did in previous docker networking tutorial. Check if docker-compose is installed by checking the version-
docker-compose --version

We will be installing the docker compose as follows-
 curl -L`uname -s`-`uname -m` > /usr/local/bin/docker-compose

Now again lets check the docker-compose version
Now docker-compose is installed. Next we will be creating the docker-compose file as follows-
version: "3"
    image: employee-consumer
      - consumer-producer
      - producer
    image: employee-producer
      - "8080:8080"
      - consumer-producer 


Docker compose file can be created at any location. We will be creating it in the employee-consumer module.
Next start the docker-compose as follows-
We can see that the docker-compose file gets executed.
We can see that - 1. If network employee-producer does not exist. It created it. 2. Started container using image employee-producer 3 Started container using image employee-consumer