This project demonstrates how to setup a basic pre-built docker container. For this project, Nginx docker image used to host a static website. Here's the project overview:
- Create a static website with HTML/CSS
- Use the official Nginx Docker image from Docker Hub
- Serve the static website using Docker and Nginx
docker-tutorial/1-nginx-website/
├── website/
│ ├── index.html
│ ├── styles.css
│ └── images/
└── README.md
Pull the official Nginx image from Docker Hub:
cd 1-nginx-website
docker pull nginx:latestNavigate to your project directory and run the following command:
docker run --name nginx-website \
-v $(pwd)/website:/usr/share/nginx/html \
-p 8080:80 \
-d nginxThis command:
- Names the container
nginx-website - Maps the local
websitedirectory to Nginx's HTML directory in the container - Maps port 8080 on your host to port 80 in the container
- Runs the container in detached mode
Open your web browser and navigate to:
http://localhost:8080/index.html
You should see the website in your browser which is running locally and if you have a domain you can also host it from your computer and anyone can access it!
To check if your container is running:
docker psTo view container logs:
docker logs nginx-websiteTo stop the Nginx container:
docker stop nginx-websiteTo remove the container:
docker rm nginx-websiteTo remove the Nginx image:
docker rmi nginx