devops-basics

Apache HTTP Server Hands-On

Hands-on guide for Apache HTTP Server using Docker

Run Apache HTTP Server in Docker

You can quickly get Apache up and running using the official Docker image.


4.1 Run a Simple Apache Container

docker run -d --name apache-server -p 8080:80 httpd:latest
# Note: Replace 8080 with the PORT works on your own machine.

4.2 Serve Custom Content

  1. Create your own index.html:
mkdir apache-content
echo "<h1>Hello from Apache in Docker!</h1>" > apache-content/index.html
  1. Run Apache with your custom HTML:
docker run -d \
  --name apache-custom \
  -p 8081:80 \
  -v $(pwd)/apache-content:/usr/local/apache2/htdocs/ \
  httpd:latest

4.3 Use a Custom Apache Configuration (Optional)

  1. Create your custom Apache config file (e.g., my-httpd.conf):
ServerName localhost

LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule dir_module modules/mod_dir.so

Listen 80
DocumentRoot "/usr/local/apache2/htdocs"
<Directory "/usr/local/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

DirectoryIndex index.html
  1. Mount the custom config file into the container:
docker run -d \
  --name apache-with-conf \
  -p 8082:80 \
  -v $(pwd)/apache-content:/usr/local/apache2/htdocs/ \
  -v $(pwd)/my-httpd.conf:/usr/local/apache2/conf/httpd.conf \
  httpd:latest

4.4 Clean Up

docker rm -f apache-server apache-custom apache-with-conf

4.5 Source & Reference