0
0
Nginxdevops~30 mins

Docker Compose with Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Docker Compose with Nginx
📖 Scenario: You want to run a simple web server using Nginx inside a Docker container. To make it easy to start and stop, you will use Docker Compose to manage the container.This project will guide you to create a Docker Compose file that runs Nginx and serves a basic web page.
🎯 Goal: Build a Docker Compose setup that runs an Nginx container serving a simple HTML page on your local machine.
📋 What You'll Learn
Create a Docker Compose YAML file named docker-compose.yml
Define a service named web that uses the official nginx:latest image
Map port 8080 on your machine to port 80 in the container
Mount a local directory ./html to /usr/share/nginx/html inside the container
Create an index.html file inside ./html with the text Hello from Nginx!
💡 Why This Matters
🌍 Real World
Docker Compose is widely used to run multiple containers easily. Nginx is a popular web server to serve websites or act as a reverse proxy.
💼 Career
Understanding Docker Compose and Nginx is essential for DevOps roles to deploy and manage web applications efficiently.
Progress0 / 4 steps
1
Create the HTML file
Create a directory called html in your project folder. Inside html, create a file named index.html with the exact content: Hello from Nginx!
Nginx
Need a hint?

Use mkdir -p html to create the folder and echo 'Hello from Nginx!' > html/index.html to create the file with content.

2
Create the Docker Compose file
Create a file named docker-compose.yml in your project folder. Define a service called web that uses the image nginx:latest.
Nginx
Need a hint?

Start your docker-compose.yml with version: '3' and define the web service with image: nginx:latest.

3
Add port mapping and volume mount
In docker-compose.yml, under the web service, add port mapping to map port 8080 on your machine to port 80 in the container. Also, mount the local ./html directory to /usr/share/nginx/html inside the container.
Nginx
Need a hint?

Use ports: with - "8080:80" and volumes: with - ./html:/usr/share/nginx/html.

4
Run Docker Compose and check output
Run docker-compose up -d to start the Nginx container. Then run curl http://localhost:8080 to get the web page content. Print the output of the curl command.
Nginx
Need a hint?

Use docker-compose up -d to start the container and curl http://localhost:8080 to fetch the page. Print the result.