Zum Hauptinhalt springen

WordPress - Docker setup

Minimal, production‑minded Docker Compose stack for WordPress + MySQL with persistent volumes and strict, env‑driven configuration.


Table of Contents


Prerequisites

ToolVersionNotes
Docker20.x+
Docker Composev2 plugin or classicUse docker compose (v2) or docker-compose (classic)

Quick Start

  1. Clone and enter the repo:
git clone https://github.com/e1pmiS/WordPress-Docker-Project.git && cd WordPress-Docker-Project
  1. Create .env from template and edit it (strong passwords!):
cp .env.example .env
  1. Start (no build step needed):
docker-compose up -d
  1. Open WordPress:
http://<host>:${HTTP_PORT:-8080}

Features

  • Official images only (wordpress:6.6-apache, mysql:8.4).
  • Env-first setup; secrets stay out of source control.
  • Persistent DB and wp-content/ volumes.
  • WordPress comes up after DB is ready (compose depends_on).

Configuration

Override them in a .env as in the .env.example file:

KeyExamplePurpose
MYSQL_ROOT_PASSWORDChangeThisRootPasswordRoot password used only for administration tasks. Keep secret.
MYSQL_DATABASEwordpressDatabase name WordPress will use.
MYSQL_USERwp_userApplication DB user (non‑root).
MYSQL_PASSWORDChangeThisAppPasswordPassword for MYSQL_USER.
HTTP_PORT8080Host port mapped to the container’s port 80.
WORDPRESS_TABLE_PREFIXwp_DB table prefix (change from default for isolation).
WORDPRESS_DEBUG0Enable verbose debugging (1) only in development.
DB_DATA_DIR./db_dataHost path persisting MySQL data.
WP_CONTENT_DIR./wp-contentHost path persisting themes/plugins/uploads.
DB_CONTAINER_NAMEwp-dbContainer name for the DB service.
WP_CONTAINER_NAMEwordpressContainer name for WordPress.
COMPOSE_PROJECT_NAMEwordpressCompose project name to keep resource names stable.

Note It’s recommended to set non‑default, strong values (especially passwords and prefixes) before any public deployment.

Operations

  • Start:
docker-compose up -d
  • Logs:
docker-compose logs -f db wordpress
  • Stop:
docker-compose down      # add -v to drop anonymous volumes
  • Update images:
docker-compose pull && docker-compose up -d