Let's Play with VPC using Docker, NGNIX & Node.js

Let's Play with VPC using Docker, NGNIX & Node.js

3 min read

The article was initially published here : https://www.linkedin.com/pulse/lets-play-vpc-using-docker-ngnix-nodejs-jahid-hasan-q9fjc/


Recently I was trying to have some hands on experience with a theoretical knowledge called VPC which stands for Virtual Private Cloud. In this article I will try to elaborate the process that how we can build services inside the vpc and how they communicate. I have created a system called pet-system which will follow the bellow's VPC architecture showing in the image diagram. It might have a flavour of microservice architecture too 😉. so let's jump into the point. 🚀

The Top Level View That I am going to develop hands on.

a simple system using vpc

VPC with docker, ngnix, nodejs


At first I have created a domain called animal-domain. Inside that domain, I have created two services called human-service and meow-service using express framework of nodejs.

Human service has the following routes

  • /health

  • /poke/meow

  • /poke/me

  • /vpc/poke/me

and Meow service has the following routes

  • /health

  • /poke/human

  • /poke/me

  • /vpc/poke/me

After testing each service locally, I have built docker images for both services with specific names . In my repo there is Dockerfile where i defined all the necessary command to build the docker image. After that i made these command.

 docker build -t human-service .        
 docker build -t meow-service .        

After the image successfully build, I created a bridge network inside the animal-domain, In that network I run the following services's images along with a ngnix server as proxy server as well as an api gateway.

When docker communicate internally within VPC, it creates DNS for each service running inside. For that inside the Animal VPC we can call http://human-service:6000 or http://meow-service:6001 directly as valid endpoint.

The Diagram for Animal VPC

Article content

Animal VPC


After the 1st VPC ready, I focused on the Plant VPC, i have created another environment as same as above (Animal VPC) with different name and different routes.

Routes in Flower Service

  1. /health

  2. /poke/fruit

  3. /poke/me

  4. /vpc/poke/me

  5. /poke/human

  6. /poke/meow

Routes in Fruit Service

  1. /health

  2. /poke/flower

  3. /poke/me

  4. /vpc/poke/me

  5. /poke/human

  6. /poke/meow

After Testing these routes locally, I build docker images separately for each services and run the services along with another ngnix proxy server and build the plant vpc.

 docker build -t flower-service .        
 docker build -t fruit-service .        

The Diagram for Plant VPC

Article content

Plant VPC.


After running the system in docker. I tested all the routes with different scenario. And It is working fine as I expected.

You will find all the source code along with `docker-compose.yml` & ngnix configure into the following repository.

Finally, Working with this type of pet system for learning purpose, It helps me to gain knowledges in various domain practically. I have learned about the

  • Networking inside the docker & how it works

  • Ngnix proxy/reverse-proxy server and how we can create gateway using this.

  • The communication between services inside the VPC that they can communicate directly.

  • Steps into Microservice Architecture.

And I achieved the confidence on those theoretical knowledge that I have learned by reading the articles, listening from the seniors etc.


Help me to catch mistakes from the article, I will fix it.

❤️ Thank you ❤️