wordpress_install_docker
WordPress Installation with Docker Compose (Non-Secure Example)
1. Project Setup
mkdir my-wordpress-project cd my-wordpress-project
2. Create docker-compose.yml
docker-compose.ymlversion: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql # Persists database data
networks:
- backend # Connects to the backend network
restart: always
environment:
# WARNING: Hardcoded passwords - for demonstration only!
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db # Ensures 'db' service starts before 'wordpress'
image: wordpress:latest
ports:
- "8000:80" # Exposes WordPress on host port 8000
restart: always
networks:
- backend # Connects to the backend network (for DB access)
- frontend # Can be used to expose WordPress to an external proxy if needed
environment:
# WARNING: Hardcoded passwords - for demonstration only!
WORDPRESS_DB_HOST: db:3306 # 'db' is the service name of the MySQL container
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {} # Defines a named volume for persistent MySQL data
networks:
frontend: {} # Defines the frontend network
backend: {} # Defines the backend network3. Starting WordPress
4. Stopping WordPress
Last updated