A specialized Docker image providing a Debian Trixie-based WordPress environment with an internal MariaDB instance and automated plugin installation, powered by the Nitro init system.
This repository is designed for creating WordPress sandbox environments. It allows you to run multiple isolated WordPress installations in parallel without conflicts, making it ideal for development and testing.
- Modern Base: Upgraded to Debian Trixie for the latest security and package updates.
- Nitro Init System: Powered by Nitro 0.8.1 for fast, lean, and reliable service management.
- Integrated Database: Includes an internal MariaDB server for zero-config startup.
- Automated Setup: Uses WP-CLI for automated site installation and plugin activation.
- Persistent Content: Supports Docker volumes for persisting themes, plugins, and uploads.
- Security Hardened: Implements PHP function restrictions and removes setuid/setgid bits to reduce attack surface.
- Protected Environments: Includes optional Basic Auth and IP restriction.
To run a new instance:
docker run -d \
--net="bridge" \
--name=wordpress \
-p 8081:80 \
-e SERVER_NAME=localhost \
-e URL="http://localhost:8081" \
-e ADMIN_NAME=admin \
-e ADMIN_PASSWORD=admin \
-e ADMIN_EMAIL=admin@domain.com \
-e PLUGINS='contact-form-7' \
-e TITLE='Wordpress-Title' \
-v wp-content:/content \
-v wordpress-db:/var/lib/mysql \
deb-wordpress:latest| Variable | Description | Default |
|---|---|---|
SERVER_NAME |
Apache ServerName | localhost |
URL |
WordPress Site URL | http://localhost:8081 |
ADMIN_NAME |
WP Admin Username | admin |
ADMIN_PASSWORD |
WP Admin Password | admin |
ADMIN_EMAIL |
WP Admin Email | admin@domain.com |
PLUGINS |
Space-separated list of plugins to install | `` |
TITLE |
Site Title | WordPress-Sample-Title |
BASIC_AUTH_ENABLED |
Enable Basic Auth (true/false) | false |
ALLOWED_IP |
IP allowed to bypass Basic Auth | `` |
- Database Access: The internal MariaDB is not exposed by default (runs on port 3306 as root/root). For production, use a separate database container.
- Database Persistence: The MariaDB data lives in
/var/lib/mysql, declared as aVOLUME. Always mount a persistent volume there (e.g.-v wordpress-db:/var/lib/mysql) — otherwise the database sits in the container's writable layer and is deleted when the container is removed (e.g. during an image rebuild /docker rm+docker run). Named volumes survive container recreation, so the site keeps its data across image updates. - Content Persistence: Mount a volume to
/contentto persist your custom themes, plugins, and uploads. On the first run, contents are copied to/var/www/html/wp-content. - Init System: This image uses Nitro to manage Apache and MariaDB, ensuring correct boot order and service reliability.
- Non-root user: Currently, the
Dockerfileusesphp:apachewhich runs as root to start Apache, then switches towww-data. However, the overall container process usually starts as root. - Filesystem Permissions: Ensuring
/var/www/htmlis only writable bywww-datawhere necessary. - Remove build-time tools: The
Dockerfilealready has someapt-get purgelogic. - Read-only filesystem: Not always possible for WP, but we can make certain parts read-only.
- Removing unnecessary packages: Already doing some
no-install-recommends.
The database is in the wordpress-db volume, so back it up before destructive operations (image rebuilds, docker rm):
# Dump to a file on the host (the image ships with mysqldump):
docker exec wordpress mysqldump -uroot -proot --all-databases > wp-backup.sql
# Restore into a (re)created container:
docker exec -i wordpress mysql -uroot -proot < wp-backup.sqlIf a running instance predates the persistence fix (its DB is in the container's writable layer, not a volume), move it to a named volume:
# 1. Dump the existing DB from the running container
docker exec wordpress mysqldump -uroot -proot --all-databases > /root/wp-migrate.sql
# 2. Recreate the container with the new image + the DB volume
docker rm -f wordpress
docker run -d --name=wordpress -v wp-content:/content -v wordpress-db:/var/lib/mysql \
-e URL="https://your.site" -e ADMIN_NAME=admin -e ADMIN_PASSWORD=... \
deb-wordpress:latest
# 3. After first-run init completes, restore the dump
docker exec -i wordpress mysql -uroot -proot < /root/wp-migrate.sqlIf you appreciate this work, please consider buying me a beer! :D
