DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk9 min

How to Run an Apache Web Server in Docker With a Dockerfile

Build a reproducible Apache container from httpd:2.4, copy your HTML into the document root, publish port 80 with Docker, and learn the bind-mount, configuration, HTTPS, versioning, and troubleshooting choices that matter.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The shortest reliable path is to build a small image from httpd:2.4, copy your website into Apache’s document root, and publish container port 80 to a host port. Create a public-html folder with an index.html file, add a two-line Dockerfile, then run docker build -t my-apache2 . and docker run -d --name my-running-app -p 8080:80 my-apache2. Open http://localhost:8080 to test it.

What this setup does

Apache HTTP Server (the httpd image) runs inside an isolated container. Your Dockerfile defines how an image is assembled: it selects a base image and copies your site into Apache’s document root. The container then listens on its internal TCP port 80. The -p 8080:80 option connects port 8080 on your computer to port 80 in the container, making the site reachable from a browser.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This pattern is useful for a static HTML/CSS/JavaScript site, a reproducible local test environment, or a release image that should run the same way on another Docker host. It does not by itself provide production TLS, backups, DNS, monitoring, or a hardened server configuration; those are separate operational concerns.

Prerequisites

  • Docker Engine or Docker Desktop is installed and the Docker daemon is running.
  • A terminal with permission to run Docker commands.
  • A project directory containing the files you want Apache to serve.
  • Port 8080 on the host is available, or you have chosen another unused host port.

Run the commands from the project directory. The final period in docker build -t my-apache2 . is significant: it tells Docker to use the current directory as the build context.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Create the project files

Recommended directory layout

apache-docker/
├── Dockerfile
└── public-html/
    └── index.html

The folder name is arbitrary. What matters is that the Dockerfile and public-html directory are inside the build context, and that the website files are inside public-html.

Add a test page

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Apache in Docker</title>
</head>
<body>
  <h1>Apache is running</h1>
  <p>This page is being served from an httpd container.</p>
</body>
</html>

Replace this file with your own site. Relative links, stylesheets, scripts, images, and subdirectories are copied along with it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Write the Dockerfile

FROM httpd:2.4
COPY ./public-html/ /usr/local/apache2/htdocs/

What FROM means

FROM httpd:2.4 selects the Apache HTTP Server base image and its default runtime configuration. Pinning the major/minor tag makes the intent clearer than using an unqualified latest tag, which can move to a different image over time.

What COPY means

COPY ./public-html/ /usr/local/apache2/htdocs/ copies the contents of your local public-html directory into the document root used by the image. Apache serves index.html at the site root, so a request for / loads that file.

The destination path is inside the container, not on your host. Keep the trailing slash on the source and destination paths as shown; it makes the intended directory-to-directory copy unambiguous.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Should you add EXPOSE 80?

You may add this documentation line:

FROM httpd:2.4
EXPOSE 80
COPY ./public-html/ /usr/local/apache2/htdocs/

EXPOSE records that the container listens on TCP port 80. It does not publish that port to your computer. A runtime mapping such as -p 8080:80 is still required for access through localhost. The instruction is optional for this example because the base image already serves on port 80, but it can make the image’s intended network port easier for people and tooling to understand.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build the image and start Apache

  1. Change into the directory containing the Dockerfile.
  2. Build an image from that directory:
    docker build -t my-apache2 .

    The -t option assigns the local name my-apache2. Docker reads the Dockerfile, downloads the base image if necessary, and creates a new layer containing your site files.

  3. Start a detached container and publish the web port:
    docker run -d --name my-running-app -p 8080:80 my-apache2

    -d runs in the background, --name gives the container a predictable name, and -p 8080:80 maps host port 8080 to container port 80.

  4. Open http://localhost:8080 in a browser. You should see the contents of public-html/index.html.

To stop the server, run docker stop my-running-app. To remove the stopped container, run docker rm my-running-app. If you rebuild the image after changing files, stop and remove the old container before starting a new one with the same name.

Understand host and container ports

Command or setting Result When to use it
-p 8080:80 Host port 8080 forwards to container port 80. Normal local development and scripts that need a predictable URL.
-p 443:443 Host port 443 forwards to container port 443. Only after Apache has been configured for HTTPS inside the container.
-P Docker publishes exposed container ports on automatically selected host ports. Temporary testing when you do not need a fixed host port.
EXPOSE 80 Documents that the image listens on container TCP port 80; it does not publish the port. Communicating the image contract to readers and tooling.

With -P, Docker chooses an ephemeral host port, so http://localhost:8080 is not guaranteed. Inspect the running container with docker ps to see the assigned mapping, then use the displayed host port in your browser. Prefer -p when documentation, bookmarks, reverse-proxy rules, or automated checks depend on a stable address.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Choose between a baked-in site and a bind mount

The Dockerfile above creates an immutable image containing the site. The official Apache image also supports mounting a host directory directly onto the document root, which is convenient while files are being edited.

Characteristic Site copied during docker build Host directory bind-mounted at runtime
Deployment reproducibility High: the image contains the exact files used for the release. Depends on the host directory and its current contents.
Edit turnaround Changes require a new image build and usually a new container. Edits on the host appear through the mounted directory without rebuilding the image.
Immutable release behavior Strong: a tagged image can be promoted unchanged. Weaker: files can change independently of the image.
Separation of content from image Content is part of the image artifact. Content remains on the host and is injected at startup.

Use a bind mount for active development

From the project directory, mount public-html over the image’s document root:

docker run -d 
  --name my-apache-dev 
  -p 8080:80 
  -v "$(pwd)/public-html:/usr/local/apache2/htdocs/" 
  httpd:2.4

The exact host-path syntax varies by shell and operating system. The essential mapping is always the host’s public-html directory to /usr/local/apache2/htdocs/ in the container. The mount hides the image’s original document-root contents while the container is running, so confirm that the host directory contains an index.html.

Use the Dockerfile image for a release or a handoff to another machine. Use the bind mount when rapid browser refreshes matter more than an immutable artifact.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Customize Apache configuration

Do not edit files inside a running container as your permanent configuration method. Export the image’s default configuration, edit it in your project, and copy the edited file into a derived image.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Export the baseline configuration

docker run --rm httpd:2.4 cat /usr/local/apache2/conf/httpd.conf > my-httpd.conf

--rm removes the temporary container after the command finishes. The resulting my-httpd.conf is now a host file you can review and modify.

Build an image with the edited configuration

FROM httpd:2.4
COPY ./my-httpd.conf /usr/local/apache2/conf/httpd.conf
COPY ./public-html/ /usr/local/apache2/htdocs/

Save this as your Dockerfile, then rebuild with a new tag:

docker build -t my-apache2-custom .
docker run -d --name my-running-app -p 8080:80 my-apache2-custom

Keep the configuration and website in version control together. If Apache fails to start after an edit, inspect the container log with docker logs my-running-app, correct the configuration, rebuild, and recreate the container.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Add HTTPS when you are ready

The official image documentation describes a certificate-and-key layout using server.crt and server.key under /usr/local/apache2/conf/. You must enable the SSL-related modules, enable conf/extra/httpd-ssl.conf in httpd.conf, and publish container port 443.

Copy certificate files into the image

FROM httpd:2.4
COPY ./my-httpd.conf /usr/local/apache2/conf/httpd.conf
COPY ./server.crt /usr/local/apache2/conf/server.crt
COPY ./server.key /usr/local/apache2/conf/server.key
COPY ./public-html/ /usr/local/apache2/htdocs/

Run the HTTPS listener

docker build -t my-apache2-https .
docker run -d --name my-running-https -p 443:443 my-apache2-https

Certificate issuance, private-key protection, renewal, hostname validation, redirect policy, and production hardening are not solved by copying files into an image. Treat those tasks as a separate deployment design, and never publish a private key in a public image registry.

Make builds reproducible

Use an intentional image tag

An unqualified latest tag can change. The Docker tutorial recommends a more specific numbered tag, and available httpd tags include 2.4.69 and 2.4, along with Alpine variants. Tags remain mutable operational inputs, so check the tag you intend to deploy and record the resulting image digest in a controlled release process.

For example, changing the first line to FROM httpd:2.4.69 communicates a concrete Apache release, while FROM httpd:2.4 follows updates within the 2.4 line. A fully digest-pinned reference offers stronger byte-for-byte repeatability, but the digest itself must be obtained from your registry workflow rather than guessed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep the build context small

Only copy the files Apache needs. Do not place private keys, local caches, editor backups, or unrelated application source in the build context. A .dockerignore file can exclude unnecessary content before Docker sends the context to the builder.

Tag releases clearly

Use a meaningful image tag such as my-apache2:site-2026-10-15 for a release and keep the exact Dockerfile and site files that produced it. Avoid silently rebuilding the same tag with different content when another environment may still depend on the old image.

Troubleshoot the common failure modes

The browser says the connection was refused

  • Confirm the container is running with docker ps. If it exited, inspect docker logs my-running-app.
  • Check the port mapping in the PORTS column. You need a mapping similar to 0.0.0.0:8080->80/tcp for the documented URL.
  • Use the actual host port from the mapping. If you started with -P, Docker probably selected a port other than 8080.
  • Check whether another process already occupies host port 8080. Choose a free port, such as -p 8081:80, and browse to http://localhost:8081.

The default Apache page appears instead of your site

  • Verify that public-html/index.html exists relative to the build command’s directory.
  • Make sure you rebuilt the image after changing the Dockerfile or site files.
  • If you used a bind mount, confirm the host path is correct and contains the intended files; a wrong or empty mount can hide the image’s copied content.
  • Remove the old container and start a new one from the newly tagged image. A running container does not automatically update when an image is rebuilt.

docker build cannot find the Dockerfile or source directory

Run pwd (or your platform’s equivalent) and list the directory contents. The Dockerfile must be inside the build context, and the relative source path in COPY ./public-html/ ... must exist beneath that context. Docker will not copy a file located outside the context.

The container exits immediately after a configuration change

Read the startup error with docker logs my-running-app. Common causes include a misspelled directive, a module that was not enabled, an invalid certificate path, or a malformed virtual-host block. Restore the exported baseline configuration, reapply one change at a time, rebuild, and test each change before adding another.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

HTTPS is not reachable

  • Confirm Apache is configured to listen on 443 and that the SSL modules and conf/extra/httpd-ssl.conf are enabled.
  • Publish the port with -p 443:443; publishing only -p 8080:80 cannot expose HTTPS.
  • Check that the certificate and key paths in the configuration match the files copied into /usr/local/apache2/conf/.
  • Use a certificate whose hostname matches the address you are testing. A self-signed certificate may trigger a browser warning even when Apache is functioning.

Operational checklist before sharing the image

  • Use a specific, reviewed httpd tag rather than relying on an unqualified latest reference.
  • Confirm the site is present at /usr/local/apache2/htdocs/ inside the built image.
  • Test the exact port mapping another operator will use.
  • Keep mutable development mounts separate from immutable release images.
  • Review custom directives and remove unnecessary modules or sample content.
  • Protect certificate private keys and do not commit them to source control or publish them in a shared image.
  • Plan logging, updates, backups of source content, TLS renewal, DNS, and a restart strategy independently of the two-line Dockerfile.

A complete minimal example

With this layout:

apache-docker/
├── Dockerfile
└── public-html/
    └── index.html

Use this Dockerfile:

FROM httpd:2.4
COPY ./public-html/ /usr/local/apache2/htdocs/

Then run:

cd apache-docker
docker build -t my-apache2 .
docker run -d --name my-running-app -p 8080:80 my-apache2

Visit http://localhost:8080. This gives you a deterministic Apache container with the website embedded in the image. When the site changes, rebuild the image and recreate the container; when files are changing constantly during development, use the documented bind-mount pattern instead.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.