Lesson: Running a Dockerized HTML Example

๐Ÿ“ 1. Checkout the Branch

This switches your working directory to the code for this lesson:

git checkout lesson-docker-0001 ls -altr cmd.exe /c start howto/index.html #will open this page, if fails just use windows file explorer

๐Ÿณ 2. Build and Run the Docker Container

๐Ÿ“ Make sure Docker Desktop is running before executing these commands.

These commands build and run a simple HTML server using Docker:

docker build -t lesson-html . docker run -d -p 8080:80 --name html-container lesson-html
โš ๏ธ Common Errors When Re-running the Container

Error: You may see this if the container already exists:

docker: Error response from daemon:
Conflict. The container name "/html-container" is already in use...
    

How to Fix:

  1. Stop the existing container:
  2. docker stop html-container
  3. Remove it:
  4. docker rm html-container
  5. Then run the container again:
  6. docker run -d -p 8080:80 --name html-container lesson-html

๐ŸŒ 3. Open in Browser

To view the running web page:

start http://localhost:8080 # Windows open http://localhost:8080 # macOS xdg-open http://localhost:8080 # Linux

๐Ÿงน 4. Stop and Remove the Container (Optional)

When done, clean up by stopping and removing the container:

docker stop html-container docker rm html-container

โฌ…๏ธ Back to Main Tutorial