Day-17 (Part-3) (Docker-compose )- Hosting Multiple Websites with Multiple Containers:
Objective:
To launch two HTML websites using two containers and the nginx web server, such that accessing the IP address of one container displays one website, and accessing the IP address of the other container with a specific path displays another website.
Steps to follow:
Set up a server environment with Docker installed.
Create two HTML websites that you want to host using your project.
Create two Docker containers, one for each website, using the Nginx image. Each container should have a unique name and IP address.
Configure the nginx web server on each container to serve the corresponding website. This involves modifying the Nginx configuration file to specify the root directory of each website and the server name for each container.
In the configuration file for the container hosting the second website, specify a location block for the "/Abhijeet" path and configure it to serve the content of the second website.
Start both containers using Docker and verify that they are running.
Test the websites by accessing the IP address of the first container in a web browser. You should see the correct website displayed.
Test the second website by accessing the IP address of the second container followed by the "/Abhijeet" path in a web browser. You should see the correct website displayed.
Create a Docker-compose file:
here I am creating a docker-compose file that will create two containers for web application hosting.
here I am creating two containers installing nginx and importing all dependencies for web hosting.
Run Docker-composed File:
docker-compose up -d
Check the status of the container:
docker ps
Enter into a container one by one and check all things:
docker exec -it <container_name> bash
Check if the website is running with import:
Copy IP address and try to access it on the browser.