codegurukool.com · Free coding tutorials & online compiler

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

Steps

  1. Make a folder with a file index.html that says Hello from Docker.
  2. Save the code as Dockerfile in the same folder.
  3. Build it: docker build -t my-site .
  4. Run it: docker run -d -p 8080:80 --name site my-site
  5. Open http://localhost:8080 in your browser.

Run it

Docker needs its engine, so this page shows the expected build result.

Challenge

Example code

FROM nginx:1.27-alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80

Run this code in the online editor

← Clean up