Run WordPress Locally with Docker

Thursday, July 18, 2019
Tags: wordpress docker

I’d like to start by thanking Josh for convincing me to go this route instead of VVV (which is particularly relevant since I’m using a pretty pedestrian laptop nowadays and Docker containers should be nicer to my RAM than virtual machines).

  1. Download and install Docker.
  2. Create a folder where all the WordPress files will live and cd into it.
  3. Create a docker-compose.yml file (shown below) in the folder.
  4. Run docker-compose up -d.
  5. Visit http://localhost:8000 and finish the installation process.

Now you can create and modify themes and plugins in their proper places within the folder you created.

Here’s how you work with your fancy Docker setup from now on:

Sources:


Save this file as docker-compose.yml in the folder you created:

version: '2'

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - '8080:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: somewordpress

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    restart: always
    volumes: ['./:/var/www/html']
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress

volumes:
  db_data: