288 words
1 minutes
🐳 Production-Ready WordPress with Docker

πŸ”§ What’s Inside This Stack?#

This setup ships with:

  • βœ… WordPress + WP-CLI support
  • βœ… Auto plugin installation via .env
  • βœ… Seamless MariaDB setup or external DB compatibility
  • βœ… Lightweight base image: php-docker-nginx:php82
  • βœ… Multi-arch support (ARM64, AMD64)

πŸ’» Supported Platforms#

Run it confidently on:

  • Apple Silicon (M1/M2)
  • AWS Graviton instances
  • Intel/AMD-based servers and desktops

πŸ“‚ Project Setup#

Step 1: Get the Files#

Create a new project directory and copy in the following:

  • docker-compose.yml
  • .env_example β†’ rename to .env

Sample docker-compose.yml#

services:
  wordpress:
    image: ghcr.io/nooblk-98/wordpress-docker:php82
    container_name: ${PROJECT_NAME}
    environment:
      WP_SITE_TITLE: ${WP_SITE_TITLE}
      WP_ADMIN_USER: ${WP_ADMIN_USER}
      WP_ADMIN_PASSWORD: ${WP_ADMIN_PASSWORD}
      WP_ADMIN_EMAIL: ${WP_ADMIN_EMAIL}
      WORDPRESS_DB_HOST: ${MYSQL_HOST}
      WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
      WORDPRESS_DB_USER: ${MYSQL_USER}
      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
      WP_PLUGINS: ${WP_PLUGINS}
      WORDPRESS_DEBUG: false
    volumes:
      - web_data:/var/www/html
    ports:
      - "8080:80"
    depends_on:
      - mariadb

  mariadb:
    image: mariadb:10
    container_name: ${PROJECT_NAME}-db
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    volumes:
      - db_data:/var/lib/mysql

volumes:
  db_data:
  web_data:

βš™οΈ Configure Environment Variables#

cp .env_example .env

Edit .env:

PROJECT_NAME=wordpress
MYSQL_DATABASE=wordpress_database
MYSQL_USER=wordpress_user
MYSQL_PASSWORD=YW08dsm0XP2cek6f
MYSQL_ROOT_PASSWORD=lb9tjjGGHTIvZZr6
MYSQL_HOST=mariadb

WP_SITE_TITLE=My WordPress
WP_ADMIN_USER=admin
WP_ADMIN_PASSWORD=secureAdmin123
WP_ADMIN_EMAIL=[email protected]

WP_PLUGINS="advanced-custom-fields all-in-one-wp-migration"

Deploy (Internal MariaDB)#

docker compose up --build -d

Once deployed:

  • WordPress is auto-installed
  • Plugins from .env are installed
  • Setup is skipped on reboot (via .wp-init-done)

πŸ”— Visit: http://localhost:8080


🌐 Use an External Database#

Want to connect to an external MySQL/MariaDB service?

  1. Set these in .env:
MYSQL_HOST=db.myhost.com
MYSQL_DATABASE=external_db
MYSQL_USER=wp_user
MYSQL_PASSWORD=securepass
  1. Comment out the mariadb section in docker-compose.yml.

  2. Start just the WordPress service:

docker compose up --build -d wordpress

Features at a Glance#

FeatureDescription
βœ… Dockerized SetupSimplifies deployment and scaling
βœ… Plugin Auto-InstallerSet once, install always
βœ… DB CompatibilityUse internal or cloud-hosted DBs
βœ… Secure ConfigurationSecrets are stored in .env files
βœ… Persistent VolumesData survives container restarts
βœ… WP-CLI IntegratedAutomation-friendly WordPress management

πŸ” Environment Variables Reference#

VariableDescription
PROJECT_NAMEContainer name
MYSQL_HOSTDB host (internal or external)
MYSQL_DATABASEWordPress DB name
MYSQL_USERWordPress DB user
MYSQL_PASSWORDWordPress DB password
WP_SITE_TITLEWebsite title
WP_ADMIN_USERWordPress admin username
WP_ADMIN_PASSWORDWordPress admin password
WP_ADMIN_EMAILWordPress admin email
WP_PLUGINSSpace-separated plugin slugs

Manage Plugins via .env#

To add or change plugins:

WP_PLUGINS="seo-by-rank-math woocommerce"

They’ll be automatically installed and activated during the first boot.


🀝 Contribute & Feedback#

Found a bug or want to suggest improvements? Contributions welcome!

πŸ”§ For more details visit my repository source in github#


nooblk-98
/
php-docker-nginx
Waiting for api.github.com...
00K
0K
0K
Waiting...

🐳 Production-Ready WordPress with Docker
https://www.itsnooblk.com/posts/wordpess-docker/
Author
Lahiru Sandaruwan Liyanage
Published at
2025-06-08
License
MIT License