This guide uses Docker Compose to run WordPress with the official Docker image.
For Docker installation, see Docker.
Create docker-compose.yml with WordPress and MySQL:
cat <<'YAML' > docker-compose.yml
services:
wordpress:
image: wordpress:latest
restart: unless-stopped
depends_on:
- db
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: change-me-to-secure-password
WORDPRESS_DB_NAME: wordpress
volumes:
- wordpress_data:/var/www/html
db:
image: mysql:8.0
restart: unless-stopped
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: change-me-to-secure-password
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db_data:/var/lib/mysql
volumes:
wordpress_data:
db_data:
YAML
Important: Replace change-me-to-secure-password with strong, unique passwords before starting.
docker compose up -d
Open http://YOUR-SERVER:8080 and complete the WordPress setup wizard.
You’ll need to set:
For production deployments:
latestFor enhanced security, add authentication keys to your compose file:
environment:
WORDPRESS_AUTH_KEY: 'unique-phrase-1'
WORDPRESS_SECURE_AUTH_KEY: 'unique-phrase-2'
WORDPRESS_LOGGED_IN_KEY: 'unique-phrase-3'
WORDPRESS_NONCE_KEY: 'unique-phrase-4'
WORDPRESS_AUTH_SALT: 'unique-phrase-5'
WORDPRESS_SECURE_AUTH_SALT: 'unique-phrase-6'
WORDPRESS_LOGGED_IN_SALT: 'unique-phrase-7'
WORDPRESS_NONCE_SALT: 'unique-phrase-8'
Generate unique keys at: https://api.wordpress.org/secret-key/1.1/salt/
To connect to an existing MySQL/MariaDB server:
services:
wordpress:
image: wordpress:latest
environment:
WORDPRESS_DB_HOST: your-db-host
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: your-password
WORDPRESS_DB_NAME: wordpress
See WordPress Configuration for detailed configuration options.
Running containers in production? We help with:
Need help? office@linux-server-admin.com or Contact Us