Deploying a microservice application using Docker Compose and AWS.

Prerequisites:

We will need an AWS account to complete this project. Create a free tier AWS Account. Click here.

GitHub repository link: Click here.

What are Microservices??

Microservices is an architectural design for building a distributed application. Microservices break an application into independent, loosely-coupled, individually deployable services.

This architecture allows for each service to scale or update without disrupting other services in the application so that applications can be continuously delivered to end users.

In this Blog, we will be building a simple distributed application running across multiple Docker containers.

ARCHITECTURE

Setting up EC2 Instance

  • Search for EC2 in the search bar

  • Click on Launch Instance

  • Give a name to your Instance

  • Click on Ubuntu and select Ubuntu 20.04 LTS (Free tier eligible)

  • Select the instance type

  • In the key-pair login, select (create new key-pair). Give a name to your key pair and click on Create. ( Make sure you download the key pair as it will be used further while connecting to the ssh ). If you are using puTTY, select .ppk

  • Click on Launch instance

  • After the instance is successfully launched in the running state, Click on connect

  • There are various ways to connect to this EC2 instance. In our case, we will be using SSH to connect the instance with the MACOS terminal.

Installing Docker

  • Docker lets you build, test and deploy applications quickly.

  • It packages software into standardized units called containers that have everything the software needs to run including library, system tools, code an d runtime.

  • Running Docker on AWS provides a highly reliable, low-cost way to build, ship, and run distributed applications at any scale.

Install Docker using the following command

curl -fsSL https://get.docker.com -o get-docker.sh
 sh get-docker.sh

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Make sure that docker is installed successfully by checking the docker version

docker --version or docker -v

Installing Docker-compose

Run the following commands in your instance terminal to install docker-compose

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

sudo mv /usr/local/bin/docker-compose /usr/bin/docker-compose

sudo chmod +x /usr/bin/docker-compose

Verify if the docker-compose is installed successfully by running the following command

docker-compose --version or docker-compose -v

Docker-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.

Clone the following repository in your instance terminal

git clone https://github.com/shravani10-tech/voting-app.git

ls
cd example-voting-app

ls

To allow the inbound traffic,

  • Click on Instance_ID on your EC2 Dashboard

  • Click on Security

  • Click on any one of the security group

  • Select 'edit Inbound rules'

  • Add the ports and Click on Save

Come back to your terminal and enter the following command

Here, docker-compose.yml is the name of the docker-compose.yml file present in our repository

Builds, (re)creates, starts, and attaches to containers for a service.

docker-compose -f docker-compose.yml up --detach

Check all the running containers

sudo docker ps

The vote app will be running at <Public IPv4 DNS address>:5000, and the results will be at <Public IPv4 DNS address>:5001.

We have successfully deployed our application using AWS and Docker-compose 🎉🤖🎊 🎉

In the next blog, we will see how to deploy the same application using Kubernetes or Helm...

Thank you for reading, if you have anything to add please send a response or add a note!