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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Build an image from the official httpd:2.4 image, copy your site into Apache’s document root, publish container port 80 to a host port, and open the published address in a browser. The smallest working setup uses a two-line Dockerfile and one build command followed by one run command.

Quick-start: run Apache on localhost

Create a new directory for the project. Inside it, create a public-html directory and put an index.html file in that directory. The resulting layout should be:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
apache-docker/
├── Dockerfile
└── public-html/
    └── index.html

Save this Dockerfile as a plain-text file named exactly Dockerfile (with no extension):

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

From the directory containing the Dockerfile, build the image and start a detached container:

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.
docker build -t my-apache2 .
docker run -d --name my-running-app -p 8080:80 my-apache2

Visit http://localhost:8080. Apache should return the contents of public-html/index.html. In the port expression 8080:80, 8080 is the port on your computer and 80 is Apache’s port inside the container.

Prepare the project files

Create the build context

Docker sends the directory specified at the end of docker build to the daemon as the build context. The dot in docker build -t my-apache2 . means “use the current directory.” Keep the Dockerfile and public-html directory under that directory so the COPY instruction can see them.

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

A minimal index.html is enough to test the server:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Apache in Docker</title>
</head>
<body>
  <h1>Apache is running</h1>
</body>
</html>

Additional HTML, CSS, JavaScript and image files can be placed anywhere below public-html. The copy operation preserves that directory structure below Apache’s document root.

Use the correct document root

The official image serves files from /usr/local/apache2/htdocs/. The trailing slash in COPY ./public-html/ /usr/local/apache2/htdocs/ copies the contents of your host directory into that document root. A file at public-html/about/index.html, for example, is requested at http://localhost:8080/about/ after the container starts.

What each Dockerfile instruction does

FROM httpd:2.4

FROM selects the base image. Here it selects the Apache HTTP Server image in the 2.4 line. The image supplies Apache, its startup behavior and the standard directories used by the image.

COPY ./public-html/ /usr/local/apache2/htdocs/

COPY adds files from the build context to the image. The source path is relative to the directory used as the build context, not relative to your shell’s unrelated working directory. The destination is Apache’s document root inside the image.

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

Optional EXPOSE

You may add this line to document the port used by the container:

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
EXPOSE 80

EXPOSE records that the container listens on TCP port 80; it does not make that port reachable from the host. You still need a runtime publication option such as -p 8080:80. A complete Dockerfile with the declaration is:

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

Leaving out EXPOSE does not stop Apache from listening on port 80. It only omits the image’s documentation of that port.

Build the image and start the container

Build

Run the build from the project directory:

docker build -t my-apache2 .

The -t my-apache2 option gives the resulting image a convenient name. The final dot supplies the build context. If Docker cannot find the Dockerfile or the public-html directory, check that you are in the expected directory and that the file is named Dockerfile exactly.

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

Run

Start the image as a background container:

docker run -d --name my-running-app -p 8080:80 my-apache2
  • -d runs the container in detached mode.
  • --name my-running-app assigns a predictable container name for later commands.
  • -p 8080:80 publishes host TCP port 8080 to container TCP port 80.
  • my-apache2 identifies the image to run.

The command returns a container ID. The container should remain running because Apache is the image’s foreground process.

Stop, restart and remove it

Use the name assigned at startup:

docker stop my-running-app
docker start my-running-app
docker rm -f my-running-app

Removing a container does not remove the image. You can create another container from my-apache2 without rebuilding unless the site files or Dockerfile have changed.

Publish Apache’s port correctly

There are two different port concepts: the port Apache uses inside the container and the port clients use on the host. Apache uses port 80 in this image. The host-side value is your choice, provided that no other process is already using it.

Option Host address behavior Best use
-p 8080:80 Always maps host port 8080 to container port 80. Local development, scripts and documentation that need a predictable URL.
-P Publishes exposed container ports to automatically selected host ports. Short-lived tests where you will discover the assigned host port dynamically.

Use -p when people or tools must know the address in advance. Use -P when avoiding host-port conflicts matters more than a stable URL. If you use -P, inspect the running container’s published-port mapping with your normal Docker container-inspection workflow before opening it in a browser.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

A host port can be changed without changing Apache’s internal port. For example, -p 9090:80 makes the site available at http://localhost:9090.

Verify that the site is running

Check the container state

List running containers and confirm that my-running-app is present and that the port mapping appears. If it is absent, list stopped containers as well; a process that exits immediately will not appear in the default running-only view.

Read Apache’s output

When a container stops unexpectedly, read its logs:

docker logs my-running-app

Startup errors, configuration mistakes and permission-related failures usually appear there. If you reused the name after an earlier test, remove the old container or choose a new name before running again.

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

Request the exact URL

Open http://localhost:8080, not http://localhost, because the example publishes host port 8080 rather than host port 80. A browser showing a different application usually means another service is listening on the address you opened, or the host port in the URL does not match the -p mapping.

Copy site files into the image or mount them at runtime?

There are two valid ways to provide content. A baked-in image copies the files during docker build. A bind mount maps a host directory into the running container. Choose based on whether you are producing a repeatable release or editing files continuously.

Characteristic Files copied into the image Bind-mounted files
Deployment reproducibility The image contains the exact site files used for that build. The running result depends on the host directory mounted at startup.
Edit turnaround Changes require a new build and a replacement or restart of the container. Edits on the host are available through the mount without rebuilding the image.
Immutable release behavior Well suited to versioned, immutable releases. Convenient for development, but content can change independently of the image.
Separation of content and image Application content and server base are released together. Apache configuration can remain in the image while site content is supplied separately.

Use a bind mount for rapid development

The official image documents mapping a host project directory to Apache’s document root with -v. From the directory that contains public-html, run:

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
docker run -d --name my-running-app -p 8080:80 -v "$(pwd)/public-html:/usr/local/apache2/htdocs/" httpd:2.4

On shells that do not support $(pwd), replace the host side of the mount with an absolute path to your public-html directory. The container still serves port 80, so the same 8080:80 publication applies.

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.

With a bind mount, edit the host files and refresh the browser. You do not need to rebuild the image for each HTML or stylesheet change. The mount hides the document-root files that were present in the image, so ensure the host directory contains the complete site you intend to serve.

Use the baked-in approach for a release artifact and the bind-mount approach for a development loop. Do not accidentally use a developer’s empty or incomplete host directory when deploying a container that is expected to be self-contained.

Customize Apache’s configuration

Export the default configuration

Start by writing the image’s default configuration to a host file:

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

The temporary container is removed automatically because of --rm. Edit my-httpd.conf on the host, keeping a backup of the original so you can compare changes or recover from a mistake.

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

Build a derived image

Create a Dockerfile that replaces the configuration in a new image:

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

If the same image also needs your website, include the site copy instruction in that Dockerfile:

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
FROM httpd:2.4
COPY ./my-httpd.conf /usr/local/apache2/conf/httpd.conf
COPY ./public-html/ /usr/local/apache2/htdocs/

Build this image from the directory containing both my-httpd.conf and public-html. Rebuild after configuration edits; a running container does not automatically acquire changes made to the Dockerfile or build-context files.

Keep configuration changes deliberate

Apache directives can alter directory access, modules, logging, virtual hosts and TLS behavior. Change only what the application requires, and retain the image’s expected paths. A configuration that refers to files outside the image or mount points will fail when deployed elsewhere.

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

Serve HTTPS with the Apache image

The official image documentation describes an HTTPS setup using a certificate and private key. Place or mount server.crt and server.key in /usr/local/apache2/conf/, enable the required SSL modules, enable conf/extra/httpd-ssl.conf, and publish container port 443:

docker run -d --name my-running-app -p 8080:80 -p 443:443 my-apache2

The exact certificate filenames, validity period, trust chain and private-key protection are operational concerns separate from the basic HTTP container. Do not treat a self-signed development certificate as a production trust solution. Protect the private key, plan renewal, and verify that the configuration points to the mounted or copied files at the paths Apache uses.

Choose and pin an image tag

An unqualified latest tag can change over time. For repeatable builds, use a specific numbered tag that your deployment process has approved. Docker Hub currently lists versioned Apache tags including 2.4.69 and 2.4, along with Alpine variants. Tags are mutable operational inputs, so check the available tag and its digest when promoting an image to a controlled environment.

The trade-off is straightforward:

  • A moving tag such as 2.4 can receive newer patch releases in the same major/minor line, reducing manual updates but changing the build input.
  • A numbered tag such as 2.4.69 makes the intended version explicit and improves repeatability, while updates require you to select and test a newer tag.
  • An Alpine variant uses a different base distribution and should be validated for compatibility with any added packages, modules or troubleshooting procedures.

Record the chosen tag in version control and rebuild deliberately when you update it. Do not assume that rebuilding the same Dockerfile always produces byte-for-byte identical output when the base tag can move.

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.

Troubleshoot common failures

“Connection refused” or a browser timeout

  • Confirm the container is running and that the published mapping is present.
  • Use the exact host port from the -p option. The example uses 8080, not 80.
  • If the container stopped, read docker logs my-running-app.
  • Check whether another process already occupies the host port. Publish a different host port, such as -p 9090:80, and browse to the matching URL.

The default Apache page appears instead of your site

  • Verify that index.html is inside public-html in the build context.
  • Check that the Dockerfile copies to /usr/local/apache2/htdocs/.
  • Rebuild the image after changing site files when using the baked-in method.
  • If you used a bind mount, verify that the mounted host directory contains the intended files; the mount masks the image’s original document-root contents.

Docker cannot find the source directory

The source in COPY ./public-html/ ... must exist beneath the directory passed as the build context. Run the build from the project directory or pass the correct context path. Do not expect Docker to copy a file located outside that context.

The container name is already in use

A stopped container still reserves its name. Stop and remove the old container, or select a different name, then run the image again.

Changes do not appear after an edit

With files copied into an image, edits on the host have no effect on an existing container. Rebuild and recreate the container. For frequent editing, use the documented bind-mount pattern instead.

Port 443 is unreachable

Publishing 443:443 is necessary but not sufficient. Apache must have SSL support enabled, the SSL configuration enabled, and readable certificate and key files at the configured paths. Check the container logs and verify each of those conditions before diagnosing the host firewall or browser.

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

Deployment checklist

  • Keep the Dockerfile, site directory and any custom configuration in a version-controlled project.
  • Use a deliberate httpd tag rather than relying on an unqualified moving tag for a controlled release.
  • Build from the intended context and inspect the resulting site before publishing it.
  • Use -p for a stable host address; reserve -P for cases where an automatically assigned port is acceptable.
  • Choose baked-in content for immutable releases and bind mounts for active development.
  • Do not publish Apache to a host port that another service needs.
  • For HTTPS, protect private keys and handle certificate renewal and production hardening as separate operational tasks.
  • Keep the container name and port mapping documented so operators can stop, inspect and replace the service predictably.

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.