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:
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:latest
Navigate 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 nginx
This command:
nginx-websitewebsite directory to Nginx’s HTML directory in the containerOpen 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 ps
To view container logs:
docker logs nginx-website
To stop the Nginx container:
docker stop nginx-website
To remove the container:
docker rm nginx-website
To remove the Nginx image:
docker rmi nginx