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.
index.html: The static HTML file served by Nginx.Dockerfile: Defines the Docker image with Nginx and theindex.htmlfile.README.md: This file, providing an overview and instructions.
- Docker: Ensure Docker is installed and running on your machine. Install Docker
- VSCode (Optional): For easier development and Docker management. Download VSCode
To get started, clone this repository to your local machine:
git clone https://github.com/yourusername/docker-webserver.git
cd docker-webservermkdir webserver-docker
cd webserver-dockerCreate 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>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;"]Run the following command to build the Docker image:
docker build -t webserver-docker .Start the Docker container with the following command:
docker run -d -p 8080:80 webserver-dockerAccess your web server at http://localhost:8080.
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-dockerIf changes are not visible, try clearing your browser cache or use incognito mode.
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-dockerThis command maps the current directory to the container's Nginx directory, reflecting changes in real-time.
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.
- Docker Documentation: https://docs.docker.com/
- Nginx Documentation: https://nginx.org/en/docs/
- VSCode Docker Extension: https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to open issues or pull requests for improvements. Contributions are welcome!