The official wordpress:latest Docker image and the docker-compose.yml from a tutorial run WordPress on a laptop in 90 seconds. None of that setup survives production. The image bundles core, plugins are written into a mutable volume by the dashboard, wp-config.php reads credentials from environment variables but the image itself doesn’t know about secrets management, and persistence assumes a single host. A production-shaped WordPress in Docker takes a different approach.
What’s happening
The reflex is to keep wordpress:latest and add volumes for wp-content/ and the database. That works until any of three things happen: a deploy needs an exact plugin version, the host runs more than one replica, or media files need to be on object storage instead of a host volume. Each of those breaks the tutorial shape.
The production-shaped WordPress in Docker treats the image as immutable code and the container as runtime configuration. Plugins and themes are baked into the image at build time via Composer. Uploads go to S3 (or a network mount). Sessions, object cache, and rate limiting go to Redis. wp-config.php reads everything from env vars set by the orchestrator. The database is external — RDS, a managed PaaS, or a separate stateful container with its own backup story.
How to verify
Inspect a running container to see whether it follows the shape:
docker inspect <container> --format '{{json .Config.Env}}' | jq
# expect WP_HOME, DB_HOST, REDIS_HOST, S3_BUCKET, etc.
docker exec <container> ls -la /var/www/html/wp-content/plugins
# expect plugin code present, owned by www-data, untouchable by the runtime user
docker exec <container> wp plugin list --status=active
If the plugins list is empty because they live in a mounted volume, the image is not self-contained — that’s the tutorial shape, not the production shape.
For the database, confirm it’s not in the same container:
docker exec <container> grep DB_HOST /var/www/html/wp-config.php
# DB_HOST should be an external hostname, not 'db' or 'localhost'
What to do
Build a production WordPress image that owns its code and reads everything else from the environment.
- Write a Dockerfile that installs Composer dependencies at build time, not at runtime:
FROM php:8.2-fpm-alpine AS builder
RUN apk add --no-cache git unzip
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
WORKDIR /app
COPY composer.json composer.lock ./
RUN composer install --no-dev --optimize-autoloader --no-scripts
FROM php:8.2-fpm-alpine
RUN apk add --no-cache mysql-client \
&& docker-php-ext-install pdo_mysql opcache
COPY --from=builder /app /var/www/html
COPY config/php-fpm.conf /usr/local/etc/php-fpm.d/zz-overrides.conf
COPY entrypoint.sh /usr/local/bin/
RUN chown -R www-data:www-data /var/www/html
USER www-data
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["php-fpm"]
-
The image contains the entire site. Build it in CI, tag with the Git SHA, push to a registry. The same image promotes from staging to production — that’s the whole point.
-
Run two containers: an Nginx (or Caddy) container that serves static files and proxies PHP requests, and the PHP-FPM container that runs your image. Or use a single container with both — both work, the split lets you scale them independently.
-
Mount no code volumes in production. The only volume is for the PHP-FPM socket if Nginx and PHP run on the same host; otherwise nothing.
-
Offload media to S3 with a plugin like
human-made/s3-uploads. The container has no local upload state — restarts and scaling don’t lose anything. -
Set every WordPress secret via env vars from the orchestrator’s secrets store:
# docker-compose.yml or k8s manifest fragment
environment:
- WP_HOME=https://example.com
- DB_HOST=db.internal.example.com
- DB_USER=wp_app
- DB_PASSWORD_FILE=/run/secrets/db_password
- REDIS_HOST=cache.internal.example.com
- WP_AUTH_KEY_FILE=/run/secrets/auth_key
secrets:
- db_password
- auth_key
*_FILE env vars (read by an entrypoint script) keep secrets off the process list. Plain env vars work too if the orchestrator’s secrets handling is solid.
- Run
wp db checkandwp cron event run --due-nowfrom the entrypoint on first start, then never again — those are init-time, not per-request work.
For full-portfolio Docker WordPress setups, see Bedrock + Composer for agencies. Stack Harbor’s Enterprise WordPress practice ships these images as a release artifact.
If a team is on wordpress:latest in production with mounted plugin volumes, we can replatform the image.