This guide uses Docker to run Apache HTTP Server.
For Docker installation, see Docker.
Create a directory to store your configuration and compose files.
mkdir -p /opt/apache
cd /opt/apache
Define a container for Apache HTTP Server.
services:
apache:
image: httpd:2.4 # Official Apache HTTP Server image
container_name: apache
ports:
- "80:80"
- "443:443"
volumes:
- ./html:/usr/local/apache2/htdocs
- ./conf/httpd.conf:/usr/local/apache2/conf/httpd.conf
- ./logs:/usr/local/apache2/logs
restart: unless-stopped
Available Official Images:
httpd:2.4 - Latest 2.4.x (recommended)httpd:2.4.66 - Specific version (latest stable)httpd:alpine - Alpine-based (smaller image)mkdir -p /opt/apache/html
echo "<h1>Apache in Docker</h1>" > /opt/apache/html/index.html
Start the container in the background.
docker compose up -d
docker compose ps
docker logs apache
Test the web server:
curl -I http://localhost
mkdir -p /opt/apache/conf
Create /opt/apache/conf/httpd.conf:
ServerRoot "/usr/local/apache2"
Listen 80
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule dir_module modules/mod_dir.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule unixd_module modules/mod_unixd.so
User daemon
Group daemon
ServerAdmin admin@example.com
ServerName localhost
ErrorLog /usr/local/apache2/logs/error_log
LogLevel warn
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog /usr/local/apache2/logs/access_log common
DirectoryIndex index.html
<Directory "/usr/local/apache2/htdocs">
Require all granted
</Directory>
For production use, configure TLS:
services:
apache:
image: httpd:2.4.66
ports:
- "80:80"
- "443:443"
volumes:
- ./html:/usr/local/apache2/htdocs
- ./conf:/usr/local/apache2/conf
- ./ssl:/etc/ssl/apache # SSL certificates
restart: unless-stopped
# View logs
docker compose logs -f apache
# Stop container
docker compose down
# Restart container
docker compose restart
# Execute commands inside container
docker exec -it apache apachectl -v
docker exec -it apache apachectl -M
httpd image from Docker Hubdocker exec apache apachectl -v# Check container status
docker compose ps
# View logs
docker compose logs apache
# Test configuration
docker exec apache apachectl configtest
# Restart if needed
docker compose restart apache
Running containers in production? We help with:
Need help? office@linux-server-admin.com or Contact Us