EXP NO:9
DATE: DOCKER COMPOSE APPLICATION
AIM:
To create a cluster of containers serving an HTML file using Docker Compose, you can use a
lightweight web server like Nginx.
PROCEDURE:
Step 1: Project Structure
Your project folder structure should look like
this: html-cluster/
├── docker-compose.yml
├── index.html
└── nginx.conf
Step 2: HTML File (index.html)
Create an HTML file named index.html:
<!DOCTYPE html>
<html>
<head>
<title>HTML Cluster</title>
</head>
<body>
<h1>Welcome to the HTML Cluster!</h1>
<p>This page is served from the cluster.</p>
</body>
</html>
Step 3: Nginx Configuration (nginx.conf)
Create an Nginx configuration file to serve the HTML file:
server {
listen 80;
AJAY VARSHAAN.K.S-71812253006
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
Step 4: Docker Compose File (docker-compose.yml)
Create a Docker Compose file to run a cluster of Nginx containers:
version: '3.9'
services:
web-node-1:
image: nginx:latest
container_name: web-node-1
volumes:
- ./index.html:/usr/share/nginx/html/index.html
- ./nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8081:80"
networks:
- html-cluster
web-node-2:
image: nginx:latest
container_name: web-node-2
volumes:
- ./index.html:/usr/share/nginx/html/index.html
- ./nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8082:80"
networks:
- html-cluster
web-node-3:
AJAY VARSHAAN.K.S-71812253006
image: nginx:latest
container_name: web-node-3
volumes:
- ./index.html:/usr/share/nginx/html/index.html
- ./nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8083:80"
networks:
- html-cluster
networks:
html-cluster:
driver: bridge
Step 5: Run the Cluster
Run the following command to start the cluster:
docker-compose up -d
Step 6: Verify the Cluster
Visit the following URLs in your browser:
http://localhost:8081
http://localhost:8082
http://localhost:8083
You should see the HTML page served from different containers.
OUTPUT:
AJAY VARSHAAN.K.S-71812253006
RESULT:
Thus creation cluster of containers serving an HTML file using Docker Compose,
Is excuted successfully.
AJAY VARSHAAN.K.S-71812253006