Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation


Docker Web Server Project

A simple Docker-based web server project using Nginx to serve static HTML content. This repository provides a step-by-step guide to setting up a basic web server, building a Docker image, and running it in a container.

Project Structure

  • index.html: The static HTML file served by Nginx.
  • Dockerfile: Defines the Docker image with Nginx and the index.html file.
  • README.md: This file, providing an overview and instructions.

Getting Started

Prerequisites

  • Docker: Ensure Docker is installed and running on your machine. Install Docker
  • VSCode (Optional): For easier development and Docker management. Download VSCode

Clone the Repository

To get started, clone this repository to your local machine:

git clone https://github.com/yourusername/docker-webserver.git
cd docker-webserver

Project Setup

1. Create the Project Directory

mkdir webserver-docker
cd webserver-docker

2. Create index.html

Create a file named index.html with the following content:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Docker Web Server</title>
</head>
<body>
    <h1>Hello, Docker!</h1>
    <p>This is a simple web server running inside a Docker container.</p>
</body>
</html>

3. Create the Dockerfile

Create a file named Dockerfile with the following content:

FROM nginx:alpine
COPY index.html /usr/share/nginx/html/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Building and Running the Docker Container

1. Build the Docker Image

Run the following command to build the Docker image:

docker build -t webserver-docker .

2. Run the Docker Container

Start the Docker container with the following command:

docker run -d -p 8080:80 webserver-docker

Access your web server at http://localhost:8080.

Updating and Troubleshooting

Updating index.html

If you modify index.html, rebuild the Docker image to reflect changes:

docker build --no-cache -t webserver-docker .

Restart the container if it’s still running:

docker stop $(docker ps -q --filter ancestor=webserver-docker)
docker rm $(docker ps -a -q --filter ancestor=webserver-docker)
docker run -d -p 8080:80 webserver-docker

Clearing Browser Cache

If changes are not visible, try clearing your browser cache or use incognito mode.

Real-Time Development Setup (Optional)

For development, you can use Docker volume binding to see changes immediately:

docker run -d -p 8080:80 -v $(pwd):/usr/share/nginx/html webserver-docker

This command maps the current directory to the container's Nginx directory, reflecting changes in real-time.

Conclusion

This project demonstrates a basic Docker setup for serving static content with Nginx. By following this guide, you’ve learned how to build, run, and update a Dockerized web server. For more advanced Docker features, consider exploring Docker Compose, multi-container setups, or integrating CI/CD pipelines.

Resources

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Feel free to open issues or pull requests for improvements. Contributions are welcome!


About

A simple Docker-based web server project using Nginx to serve static HTML content. This repository provides a step-by-step guide to setting up a basic web server, building a Docker image, and running it in a container.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages