Run Apache in Docker Example Host Your Website |Video upload date:  · Duration: PT7M51S  · Language: EN

Learn how to serve a local website using the official Apache httpd Docker image with a bind mount and port mapping

Want to host a tiny website on your machine without building a custom image every five minutes like a chaotic chef rewriting the recipe? This guide walks through using the official Apache httpd Docker image with a bind mount so edits show up instantly in the browser. It is simple, fast, and wonky only when you forget which port you already used for a million apps.

What you will get

By the end you will have a running Apache server inside a container that serves files from a host folder. Edit files locally and see changes live in the browser while you pretend this was effortless.

Create the site folder and index file

Make a folder for your site. Keep the document root shallow so Apache can find it and you can find your dignity.

mkdir site
printf "<h1>Hello from Docker Apache</h1>" > site/index.html

Run Apache with port and volume mapping

Use the official httpd image and bind mount your local site folder into Apache's document root. The command below maps host port 8080 to container port 80 and mounts ./site as the server root.

docker run -d -p 8080:80 -v $(pwd)/site:/usr/local/apache2/htdocs httpd

If you are on Windows use an absolute path for the volume. If you are on Linux and permission drama starts, try running the command with sudo or fix ownership on the host folder.

Why this works

  • The -p flag exposes the container port to your host so your browser can find it.
  • The -v bind mount makes files on your host visible inside the container immediately.
  • Running detached with -d keeps the container alive while you fiddle with files.

Open your browser and test

Visit http://localhost:8080 and admire your handiwork. If nothing appears first check that the container is running.

docker ps

Edit files and see live updates

Edit site/index.html with your editor of choice. Because the folder is mounted, Apache will serve the modified files instantly. No rebuild required. This keeps a fast dev feedback loop and fewer reasons to rage at Docker.

Common problems and how to fix them

  • Container exited immediately: check logs with docker logs <container id or name> to see why it crashed.
  • Page does not load: verify you used the right port and that no other service is already listening on 8080. Pick another unused port like 8081 if needed and rerun the container.
  • Files do not update or show permission denied: fix ownership on the host with chown or pick a safer folder. On Linux a common fix is chown -R $(id -u):$(id -g) site.
  • Windows path issues: use an absolute Windows path for the -v argument or the Docker Desktop shared drives feature.

Quick troubleshooting commands

docker ps -a
docker logs <container id or name>
docker port <container id or name>

When to build a custom image

Bind mounts are perfect for development and live editing. If you need custom modules, configuration files in the image, or repeatable production builds then make a Dockerfile and bake them in. For quick testing and local hosting keep the mount and move fast.

If anything breaks remember this checklist in order: is the container running, is the port free, are your host file permissions sane, and did you name the folder correctly. If the problem persists try the logs before composing a dramatic tweet about Docker.

Now go edit index.html and reload the page. Live reload not included but highly encouraged via your editor or a live reload tool if you enjoy automation and fewer manual F5s.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.