Alpine-based image that ships Apache httpd, PHP and Git so you can drop a PHP app in a container.
583
Alpine-based image that ships Apache httpd, PHP (with a curated set of common modules) and Git so you can drop a PHP application in a container and immediately clone, serve, and update it. The image was created with “ship-it-to-the-client” scenarios in mind, where you need a reproducible stack that remains lightweight and easy to automate.
git clone private repos on first boot./data, making it trivial to persist sources, logs, and config on the host.genkey, fix-permission, error-log) handle repetitive setup tasks inside the container.renatomb/alpine-apache-php-git.Pick a container name (mywebapp) and host port (8888) then launch the image. Two common workflows are shown below.
docker run -d -p 8888:80 --name mywebapp renatomb/alpine-apache-php-git
/data volume on the hostdocker run -d \
-p 8888:80 \
-v "$(pwd)/data:/data" \
--name mywebapp \
renatomb/alpine-apache-php-git
Mounting /data lets you edit sources, inspect logs, or back up configuration directly from the host. Replace $(pwd)/data with any absolute path that suits your setup.
The first boot runs setupvol, generates SSH keys, and ensures /data is owned by the apache user before starting httpd in the foreground.
Everything that matters is under /data, meaning a single bind mount (or Docker volume) keeps stateful pieces safe:
| Path (in container) | Typical contents | Host path when mounted |
|---|---|---|
/data/localhost | Virtual host roots (htdocs, etc.) | …/data/localhost |
/data/etc | Apache configuration files | …/data/etc |
/data/log | httpd logs (access.log, error.log, …) | …/data/log |
/data/ssh | Shared SSH keypair + config | …/data/ssh |
The image rewires /etc/apache2, /var/log/apache2, /var/www/.ssh, and /var/www/localhost to symlink into /data so that Apache and your application always read/write from the persistent volume.
Every helper lives in /usr/local/bin inside the container and is available via docker exec mywebapp <command>.
| Command | Purpose |
|---|---|
pubkey | Prints (and ensures the existence of) the shared SSH public key located at /data/ssh/id_ed25519.pub. |
| `genkey [force | copy]` |
fix-permission | Recursively sets /data ownership to the apache user/group; run after manipulating files as root. |
error-log | Tails the current Apache error.log to your terminal. |
clear-log | Truncates error.log if it has grown too large. |
install <apk packages…> | Thin wrapper around apk add --no-cache for installing extra Alpine packages at runtime. |
start | Internal bootstrapper that runs setupvol, genkey, and fix-permission before Apache starts. |
Private repositories usually require the container to expose its public key:
# Show the current public key
docker exec mywebapp pubkey
# Regenerate (removes the old pair)
docker exec mywebapp genkey force
# Re-copy a host-edited key back to /root/.ssh
docker exec mywebapp genkey copy
apache and root users share the same SSH keypair, so PHP code can call Git directly if needed.docker exec:docker exec mywebapp git clone [email protected]:<user>/<repo>.git /data/localhost/htdocs
root, run docker exec mywebapp fix-permission afterward so Apache can read and write the files without permission issues.Need another PHP extension or system utility? Use the bundled helper (which delegates to apk add):
docker exec mywebapp install php-zip
For package names, refer to the Alpine Packages index.
Minimal stack (web + MariaDB) using Compose:
services:
db:
image: mariadb
command: --default-authentication-plugin=mysql_native_password --sql_mode="" --lower_case_table_names=1
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: areallystrongpassword
volumes:
- ./mysql_data:/var/lib/mysql
- ./mysql_import:/home/import
networks:
- websvcs
websys:
image: renatomb/alpine-apache-php-git:php8.3
restart: always
ports:
- "80:80"
volumes:
- ./sistema/data:/data
- ./sistema/conf:/etc/apache2/
networks:
- websvcs
depends_on:
- db
networks:
websvcs:
Adjust the paths so they match your host layout. Copy ./sistema/conf from a running container if you need to tweak Apache before committing changes back to version control.
This image is designed for controlled networks (lab, intranet, on-site customer servers). Before exposing it to the public internet, review and harden the following defaults:
/data/ssh.root and apache for convenience.github.com and bitbucket.org to simplify unattended clones.httpd.conf plus AllowOverride All; review modules, users, and TLS settings as needed.Nothing prevents you from hardening these items—feel free to bake your own derivative image, swap the setupvol logic, or manage keys externally if you require stricter controls.
Please check alpine-apache-php-git repository tags to see all available PHP versions.
Do whatever you want.
Renato Monteiro Batista is a Brazilian Computer Engineer, if you like this kind of project feel free to get in touch.
Inspired by gliderlabs/alpine and httpd, standing on the shoulders of the Alpine Linux community.
Content type
Image
Digest
sha256:de95ba069…
Size
29.6 MB
Last updated
10 months ago
docker pull renatomb/alpine-apache-php-git