Docker + WordPress

Managing development projects on a number of web hosting providers with different technologies such as NGINX, LiteSpeed or other?

Containerizing your work keeps things on your local machine seperate and isolated from system values and such.

In this example, we’ll be running WordPress, mySQL & phpMyAdmin

Create DockerFile

Within a new folder, create a docker-compose.yaml file

version: '3'

services:
  # Database
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:
      - wpsite
  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - '8090:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: password 
    networks:
      - wpsite
  # WordPress
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - '8080:80'
    restart: always
    volumes: ['./:/var/www/html']
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    networks:
      - wpsite
networks:
  wpsite:
volumes:
  db_data:

WordPress will run on: http://localhost:8080

phpMyAdmin will run on http://localhost:8090

Build it

docker-compose up -d

Stop it

docker-compose down

Resources:

Leave a Comment