Hands-on Microservices With Docker on AWS (Part 1)

Part 1, Part 2, Part 3, Part 4

Introduction

In this article, we will talk about how to setup a microservices environment with Docker on AWS. If you do not know about Docker, please visit my previous article first.

Solution Diagram

Lab 1 Architecture

In this lab, we will firstly containerize our application – Mythical Mysfits. The Dockerfile is prepared, we will just simply run some commands to see the results.

Create AWS Cloud9

For convenience, please click here to setup AWS Cloud9 through CloudFormation. The default instance size is t2-small.

Click Next and Next.

IAM resources acknowledgement

Then we check the acknowledgement and create stack.

After creation, we click on output and click the Cloud9Env link.

Paste below command to clone the repository and configure the setting.

git clone https://github.com/manbobo2002/amazon-ecs-mythicalmysfits-workshop.git
cd amazon-ecs-mythicalmysfits-workshop/workshop-1
script/setup

Containerize the Application

Now we paste below command to kick start the Dockerfile.

cd app/monolith-service
docker build -t monolith-service .

After building, we can run our application by listening 8000 port.

docker run -p 8000:80 -e AWS_DEFAULT_REGION=us-east-1 -e DDB_TABLE_NAME=Table-mysfits-fargate monolith-service

Now we open a new terminal.

We can use curl to test our application is healthy or not.

curl http://localhost:8000

We can also use below command to get the database value.

curl http://localhost:8000/mysfits

If we want to use single terminal to test our application, it is ok. Paste below command and replace with your container id.

docker run -d -p 8000:80 -e AWS_DEFAULT_REGION=us-east-1 -e DDB_TABLE_NAME=Table-mysfits-fargate monolith-service
docker ps
curl localhost:8000
docker logs {your container id}

We can go to ECR and see our container images are stored here.

We copy the mono URI.

Paste below command to push our container to the repositories.

docker tag monolith-service:latest ECR_REPOSITORY_URI:latest
docker push ECR_REPOSITORY_URI:latest

There is a new image in our repository now.

Leave a Reply