wordpress_install_docker

Home

WordPress Installation with Docker Compose (Non-Secure Example)

This guide demonstrates how to set up a WordPress instance along with a MySQL database using Docker Compose. Docker Compose is a tool for defining and running multi-container Docker applications.

Important Security Note: This example uses hardcoded passwords and is intended for local development or demonstration purposes only. Do not use this configuration in a production environment without securing it properly.

For more information and best practices, refer to the official Docker documentation: https://docs.docker.com/compose/wordpress/

1. Project Setup

  1. Create a new directory: Create a dedicated directory on your local machine for this WordPress project. This will hold your docker-compose.yml file.

    mkdir my-wordpress-project
    cd my-wordpress-project

2. Create docker-compose.yml

Create a file named docker-compose.yml in your project directory and paste the following content into it. You can use any text editor (like vi, nano, VS Code, etc.).

version: '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 network

(Added comments within the YAML to explain key parts and reiterate the security warning.)

3. Starting WordPress

Navigate to your project directory in the terminal and run the following command to start your WordPress application:

You should be able to access your new WordPress site by navigating to http://localhost:8000 in your web browser.

4. Stopping WordPress

When finished, you can stop the services and remove the containers, networks, and volumes created by docker-compose up.

  1. To stop and remove containers and networks:

  2. To also remove the db_data volume (deletes your WordPress data):

Home

Last updated