Home › Docker Tutorial › Live project: Containerize a website
Live project: Containerize a website
Package a web page in your own image and serve it.
Turn a plain web page into a Docker image that anyone can run with one command.
What you will build
- A one-page website
- A Dockerfile based on nginx
- A running container on port 8080
Steps
- Make a folder with a file
index.htmlthat says Hello from Docker. - Save the code as
Dockerfilein the same folder. - Build it:
docker build -t my-site . - Run it:
docker run -d -p 8080:80 --name site my-site - Open
http://localhost:8080in your browser.
Run it
Docker needs its engine, so this page shows the expected build result.
Challenge
- Add a CSS file and copy it into the image.
- Push the image to Docker Hub.
- Run the same site with Docker Compose.
Example code
FROM nginx:1.27-alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80Run this code in the online editor
← Clean up