Add Docker development environment

Multistage Dockerfile (WooCommerce download, wp-bootstrap npm build,
Composer deps, WordPress runtime), Compose stack with MariaDB, and
auto-setup entrypoint that installs WordPress and activates the theme
on first boot.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 11:59:20 +01:00
parent 404f3a7264
commit 624de0cae6
10 changed files with 270 additions and 0 deletions

19
docker/.env-dist Normal file
View File

@@ -0,0 +1,19 @@
# Database
MYSQL_ROOT_PASSWORD=rootpass
MYSQL_DATABASE=wordpress
MYSQL_USER=wordpress
MYSQL_PASSWORD=wordpress
# WordPress
WP_PORT=8080
# Auto-setup (runs on first boot, set to 0 to disable)
WP_AUTO_SETUP=1
WP_URL=http://localhost:8080
WP_TITLE=WC Bootstrap Dev
WP_ADMIN_USER=admin
WP_ADMIN_PASSWORD=admin
WP_ADMIN_EMAIL=admin@example.com
# Build args (used during `docker compose build`)
# WOOCOMMERCE_VERSION=latest

70
docker/Dockerfile Normal file
View File

@@ -0,0 +1,70 @@
###############################################################################
# Stage 1 — Download WooCommerce from WordPress.org
###############################################################################
FROM alpine:3.21 AS woocommerce
RUN apk add --no-cache curl unzip jq
ARG WOOCOMMERCE_VERSION=latest
RUN set -ex; \
if [ "$WOOCOMMERCE_VERSION" = "latest" ]; then \
URL=$(curl -sSf "https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=woocommerce" \
| jq -r '.download_link'); \
else \
URL="https://downloads.wordpress.org/plugin/woocommerce.${WOOCOMMERCE_VERSION}.zip"; \
fi; \
curl -sSfL -o /tmp/woocommerce.zip "$URL"; \
unzip -q /tmp/woocommerce.zip -d /tmp/plugins; \
rm /tmp/woocommerce.zip
###############################################################################
# Stage 2 — Build wp-bootstrap theme assets
###############################################################################
FROM node:20-alpine AS wp-bootstrap-assets
COPY --from=wp-bootstrap . /build
WORKDIR /build
RUN npm ci && npm run build \
&& rm -rf node_modules src .git .gitea .github .vscode .claude .idea \
CLAUDE.md PLAN.md package.json package-lock.json .editorconfig \
releases .gitignore
###############################################################################
# Stage 3 — Install Composer dependencies for both themes
###############################################################################
FROM composer:2 AS composer
COPY --from=wp-bootstrap-assets /build /themes/wp-bootstrap
WORKDIR /themes/wp-bootstrap
RUN composer install --no-dev --optimize-autoloader --no-interaction
COPY . /themes/wc-bootstrap
WORKDIR /themes/wc-bootstrap
RUN composer install --no-dev --optimize-autoloader --no-interaction
###############################################################################
# Stage 4 — Final WordPress image
###############################################################################
FROM wordpress:6.9.1-php8.4-apache AS wp_runtime
RUN curl -sSfL -o /usr/local/bin/wp \
https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
&& chmod +x /usr/local/bin/wp
COPY --from=woocommerce /tmp/plugins/woocommerce \
/var/www/html/wp-content/plugins/woocommerce
COPY --from=composer /themes/wp-bootstrap \
/var/www/html/wp-content/themes/wp-bootstrap
COPY --from=composer /themes/wc-bootstrap \
/var/www/html/wp-content/themes/wc-bootstrap
COPY --link --chmod=0755 docker/setup.sh /usr/local/bin/setup.sh
COPY --link --chmod=0755 docker/entrypoint.sh /usr/local/bin/wc-entrypoint.sh
ENTRYPOINT ["wc-entrypoint.sh"]
CMD ["apache2-foreground"]

21
docker/entrypoint.sh Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
#
# Wrapper entrypoint: runs first-time WordPress setup in the background,
# then hands off to the official WordPress entrypoint.
#
# Set WP_AUTO_SETUP=0 to disable automatic setup.
#
if [ "${WP_AUTO_SETUP:-1}" = "1" ]; then
(
cd /var/www/html
until [ -f wp-config.php ]; do sleep 2; done
sleep 3
if ! wp core is-installed --allow-root 2>/dev/null; then
setup.sh
fi
) &
fi
exec docker-entrypoint.sh "$@"

47
docker/setup.sh Normal file
View File

@@ -0,0 +1,47 @@
#!/bin/bash
#
# First-run setup: installs WordPress, activates WooCommerce and wc-bootstrap.
#
# Usage:
# docker compose exec wordpress setup.sh
#
set -euo pipefail
WP_URL="${WP_URL:-http://localhost:8080}"
WP_TITLE="${WP_TITLE:-WC Bootstrap Dev}"
WP_ADMIN_USER="${WP_ADMIN_USER:-admin}"
WP_ADMIN_PASSWORD="${WP_ADMIN_PASSWORD:-admin}"
WP_ADMIN_EMAIL="${WP_ADMIN_EMAIL:-admin@example.com}"
cd /var/www/html
# Wait for WordPress files (entrypoint copies them on first boot)
until [ -f wp-config.php ]; do
echo "Waiting for WordPress to initialize..."
sleep 2
done
if ! wp core is-installed --allow-root 2>/dev/null; then
echo "Installing WordPress..."
wp core install \
--url="$WP_URL" \
--title="$WP_TITLE" \
--admin_user="$WP_ADMIN_USER" \
--admin_password="$WP_ADMIN_PASSWORD" \
--admin_email="$WP_ADMIN_EMAIL" \
--skip-email \
--allow-root
fi
echo "Activating WooCommerce..."
wp plugin activate woocommerce --allow-root 2>/dev/null || true
echo "Activating wc-bootstrap theme..."
wp theme activate wc-bootstrap --allow-root 2>/dev/null || true
echo ""
echo "Setup complete!"
echo " URL: $WP_URL"
echo " Admin: $WP_URL/wp-admin/"
echo " User: $WP_ADMIN_USER"
echo " Password: $WP_ADMIN_PASSWORD"