Skip to content

Deployed a simple webpage using Apache HTTP Server in Docker, serving static content via a containerized httpd instance. Used port mapping, volume mounts, and file transfer techniques for efficient web hosting.

Notifications You must be signed in to change notification settings

Surajkumar4-source/Serving_Webpage_from_Docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Serving a Webpage with Apache HTTP Server in Docker

Overview

This project demonstrates deploying a simple webpage using the official Apache HTTP server Docker image (httpd). The task involves creating a directory, writing an index.html file, and running a container to serve the webpage. We'll map the container's HTTP port to a port on the host system for easy access.

What We Implemented

step 1. Directory Creation

  • First, create a directory to organize the project files:
mkdir suraj
cd suraj

step 2. Create the index.html File

  • Create an index.html file with basic HTML content:
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Web Page</title>
</head>
<body>
    <h1>Welcome to My Suraj Page</h1>
    <p> This is a simple HTML page served by Apache server inside a Docker container</p>
</body>
</html>

step 3. Run the Apache HTTP Server with Docker

Option 1: Using a Volume to Serve the File

  • Run the container and map your index.html file to the container's web root:
docker run -d -p 8200:80 --name my-httpd-container -v $(pwd)/index.html:/usr/local/apache2/htdocs/index.html httpd:latest
  • -d: Runs the container in detached mode.

  • -p 8200:80: Maps port 8200 on the host to port 80 in the container.

  • --name my-httpd-container: Names the container my-httpd-container.

  • -v $(pwd)/index.html:/usr/local/apache2/htdocs/index.html: Mounts the local index.html file to the container's web server document root.

  • httpd:latest: Uses the latest version of the official Apache HTTP server image.

    Option 2: Copying the File into a Running Container

    • Alternatively, copy the index.html file into a running container:

1. Start a container from the httpd image:


docker run -d -p 8200:80 --name my-httpd-container httpd:latest

2. Copy the index.html file into the container:

docker cp index.html my-httpd-container:/usr/local/apache2/htdocs/index.html

step 4. Access the Webpage

Once the container is running:

  • Open a browser and navigate to http://localhost:8200.
  • You should see the content of the index.html file: "Welcome to Suraj's Page".


Detailed Explanation:

  1. Why Use the Volume Mount (-v)?

    • Changes made to the local index.html file will immediately reflect on the container, making it easier for testing and development.
  2. Why Use docker cp?

    • This is useful when a container is already running, and you want to copy files into it without restarting.
  3. Apache HTTP Server (httpd) in Docker:

    • httpd is a lightweight and efficient web server image provided officially on Docker Hub.
    • The web root for httpd in the container is /usr/local/apache2/htdocs.
  4. Stopping and Removing the Container:

  • To stop the container:
docker stop my-httpd-container
  • To remove the container:
docker rm my-httpd-container


What I Learned

  1. Docker Fundamentals:
  • Running containers using the docker run command.
  • Mapping host ports to container ports for web accessibility.
  • Using volume mounts (-v) and docker cp to transfer files.
  1. Serving Static Content:
  • Using the httpd image to serve HTML files.
  1. Container Management:
  • Starting, stopping, and managing Docker containers.



------------------Screnshots--------------------



Alt text for image



Alt text for image



Alt text for image







👨‍💻 𝓒𝓻𝓪𝓯𝓽𝓮𝓭 𝓫𝔂: Suraj Kumar Choudhary | 📩 𝓕𝓮𝓮𝓵 𝓯𝓻𝓮𝓮 𝓽𝓸 𝓓𝓜 𝓯𝓸𝓻 𝓪𝓷𝔂 𝓱𝓮𝓵𝓹: [email protected]


About

Deployed a simple webpage using Apache HTTP Server in Docker, serving static content via a containerized httpd instance. Used port mapping, volume mounts, and file transfer techniques for efficient web hosting.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published