Skip to content

Instantly share code, notes, and snippets.

@larodiel
Last active July 30, 2021 23:46
Show Gist options
  • Save larodiel/ec8379d47b9db50e8ae3dd175029d96e to your computer and use it in GitHub Desktop.
Save larodiel/ec8379d47b9db50e8ae3dd175029d96e to your computer and use it in GitHub Desktop.
Docker Compose to Wordpress, MySQL, wp-cli & phpMyAdmin

Wordpress, wordpress-cli, phpMyAdmin

This file will setup Wordpress, wordpress-cli & PHPMyAdmin with a single command. Add the code below to a file called "docker-compose.yml" and run the command

#To Start
$ docker-compose up -d

# To Stop
$ docker-compose down --volumes
#wp-cli example
$ docker-compose run --rm wpcli wp db optimize
http://localhost:9080/ #phpMyAdmin
http://localhost:8080/ #Wordpress

version: '3.1'

services:
  #Wordpress
  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      #Wordpress ENV Variables
      WORDPRESS_DB_HOST: db #Name of DB image
      WORDPRESS_DB_USER: mydbusername #DB username defined on DB image
      WORDPRESS_DB_PASSWORD: root #DB password defined on DB image
      WORDPRESS_DB_NAME: mydbname #DB name defined on DB image
      WORDPRESS_TABLE_PREFIX: wp_ #table prefix
    volumes:
      - ./:/var/www/html
    networks:
      - wpsite
      
  #Database    
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: mydbname
      MYSQL_USER: mydbusername
      MYSQL_PASSWORD: root
      MYSQL_ROOT_PASSWORD: root 
    volumes:
      - db:/var/lib/mysql
    networks:
      - wpsite
      
  #WP CLI
  wpcli:
    image: wordpress:cli
    working_dir: /var/www/html
    environment:
      WORDPRESS_DB_HOST: db #Name of DB image
      WORDPRESS_DB_USER: mydbusername #DB username defined on DB image
      WORDPRESS_DB_PASSWORD: root #DB password defined on DB image
      WORDPRESS_DB_NAME: mydbname #DB name defined on DB image
      WORDPRESS_TABLE_PREFIX: wp_ #table prefix
    volumes:
      - ./:/var/www/html
    depends_on:
      - db
      - wordpress
    networks:
      - wpsite
      
  #phpMyAdmin
  phpmyadmin:
    image: phpmyadmin
    restart: always
    ports:
      - 9080:80
    depends_on:
        - db
    environment:
      #PMA_ARBITRARY = 1
      MYSQL_ROOT_PASSWORD: root
      PMA_HOST: db
    networks:
      - wpsite

volumes:
  wordpress:
  db:
networks:
  wpsite:
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment