Docker Containerization Guide (Static HTML Project using WSL + Ubuntu)

This guide explains, in simple language, how to deploy an HTML website using Docker inside WSL Ubuntu.

1️⃣ Go to Your Project Folder

Your HTML files can exist in Windows. Open Ubuntu terminal and navigate to them:

cd /mnt/c/Users/YourName/Desktop/myproject

Use ls to ensure index.html is inside the directory.

2️⃣ Create Dockerfile in That Folder

Create a Dockerfile using:

nano Dockerfile

Paste the following:

FROM nginx:latest
COPY . /usr/share/nginx/html

Save → CTRL + S, Exit → CTRL + X.

3️⃣ Build the Docker Image

docker build -t my-html-site .

This creates an image called my-html-site.

4️⃣ Run the Docker Container

Expose port 3000 and map it to nginx port 80:

docker run -d -p 3000:80 --name my-container my-html-site

5️⃣ Open Your Website

Go to:

http://localhost:3000

Your HTML website is now running inside a Docker container 🎉

⚠️ COMMON DOCKER ERRORS & SOLUTIONS

❌ Error 1: docker: command not found

Reason: Docker Desktop is not connected with WSL.

Solution:

❌ Error 2: Port Already in Use

bind: port is already allocated

Solution: Use another port:

docker run -d -p 3001:80 --name my-container my-html-site

❌ Error 3: Container Name Already Exists

Conflict: The container name is already in use

Solution A — Remove old container:

docker rm -f my-container

Solution B — Use new name:

docker run -d -p 3000:80 --name my-container-v2 my-html-site

❌ Error 4: HTML Not Loading

Reasons:

Fix:

docker ps

Check correct container & port mapping.