"Dockerized 2-Tier Application with Custom Network"
Ritul Gupta
2 min read
Table of contents
- Step-1 Install Docker on your system.
- Step-2 Clone the project source code using the following command:
- Step-3 Create a custom bridge network with the name "own-network":
- Step-4 Build the Docker images for your application using the Docker build command:
- Step-5 Run the containers within your custom network:
- Step-6 Copy the public IP and access the application using http://<public_ip>:<port>
- Step-7 To test connectivity between containers, access one of the containers and ping the other container's website:
- Step-8 Create a MongoDB container on your custom network:
- Step-9 Check if the tasks API inside MongoDB is accessible from the container using the Public IP:
- <mark>Summary: I have created a custom bridge network named "own-network," where two containers are running on the same network and can communicate with each other. Additionally, I've verified that the MongoDB container has access to the internet and tested the connectivity between containers and accessing the MongoDB tasks API.</mark>
Step-1 Install Docker on your system.
sudo apt-get update -y
sudo apt-get install docker.io -y
sudo usermod -aG docker $USER
sudo reboot
Step-2 Clone the project source code using the following command:
git clone https://github.com/LondheShubham153/microservices-k8s.git
Step-3 Create a custom bridge network with the name "own-network":
docker network create custom_name
Step-4 Build the Docker images for your application using the Docker build command:
docker build -t your_image_name:tag /path/to/Dockerfile
Step-5 Run the containers within your custom network:
docker run -d -p 5000:5000 --name container1 --network custom_name your_image_name:tag
Step-6 Copy the public IP and access the application using http://<public_ip>:<port>
Step-7 To test connectivity between containers, access one of the containers and ping the other container's website:
docker exec -it container_id sh
ping <website_url>
Step-8 Create a MongoDB container on your custom network:
docker run --name mongodb_container --network own-network -d mongo
Step-9 Check if the tasks API inside MongoDB is accessible from the container using the Public IP:
Summary: I have created a custom bridge network named "own-network," where two containers are running on the same network and can communicate with each other. Additionally, I've verified that the MongoDB container has access to the internet and tested the connectivity between containers and accessing the MongoDB tasks API.
Thank you
1
Subscribe to my newsletter
Read articles from Ritul Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ritul Gupta
Ritul Gupta
Im looking for an opportunity to start a career in Cloud Technologies where I can enhance my knowledge and skills. Having knowledge and hands-on on Azure Cloud, AWS & Open Source tools - Docker, Kubernetes, Jenkins, Source Version Control, CI/CD Pipelines, and Script.