Minimal, non-root Apache HTTP Server on Alpine with env-driven config and optional modules.
4.2K
Apache HTTP Server is a widely used web server that delivers websites. Running it in a container (e.g., with Docker) is practical because it isolates the application and its dependencies, making it portable.
| Plattform | Link |
|---|---|
| container-apache | |
| Apache |
For security reasons, Apache should not run as root inside a container. By default, many container processes run as root, which poses a high risk. If a vulnerability is exploited, an attacker could gain full control over the host server.
By starting the Apache process as a non-root user, you significantly limit the potential damage in case of an attack. The attacker would only have the restricted privileges of that user and couldn't access or manipulate the underlying host system.
While containers offer good isolation, they are not immune to attacks. Key security practices include:
To avoid permission issues with bind mounts, you can build the image so that the apache user inside the container uses the same UID/GID as your host user.
docker build --build-arg APACHE_UID=$(id -u) --build-arg APACHE_GID=$(id -g) -t httpd:latest .APACHE_UID=100, APACHE_GID=101.Note: The container still runs as apache (not root). The Apache config also uses User apache/Group apache.
apk upgrade during buildYou can opt-in to upgrading all base packages during build via a build arg:
docker build --build-arg APK_UPGRADE=true -t httpd:latest .APK_UPGRADE=false (no upgrade for reproducibility)The Dockerfile conditionally runs apk update && apk upgrade before installing required packages.
You can set the image metadata version label via a build arg:
docker build --build-arg IMAGE_VERSION=$(git describe --tags --always --dirty) -t httpd:latest .docker build --build-arg IMAGE_VERSION=$(git rev-parse --short HEAD) -t httpd:latest .This value is written to label org.opencontainers.image.version.
The image also writes the version into a file inside the container for easy runtime inspection:
/etc/image-versioncat /etc/image-versionThis mirrors the IMAGE_VERSION build arg and stays immutable at runtime.
To enable SSL support, the following environment variables must be provided:
Certificates can be mounted into the container using a volume, for example:
./certificates:/etc/certs:ro
If SSL_CERTIFICATE_FILE and SSL_CERTIFICATE_KEY_FILE are not set, a default self-signed certificate will be loaded. This should be replaced with a valid certificate for production use.
services:
webinternal:
container_name: webinternal
image: nmeyer99/apache-httpd:latest
networks:
- internal
ports:
- "8001:8080"
environment:
MOD_AUTOINDEX: true
volumes:
- rootfs:/app
Content type
Image
Digest
sha256:45d5e7d87…
Size
9.6 MB
Last updated
1 day ago
docker pull nmeyer99/apache-httpd