Building an environment for WordPress, MySQL and phpMyAdmin with Docker Compose on EC2

Overview

I built an environment for WordPress, MySQL and phpMyAdmin by using Docker Compose on EC2 on AWS, so make a note so that I can review it immediately. The installation procedure of Docker is omitted. I haven't written the EC2 instance connection yet, so I'll post it separately.

I searched for "docker wordpress" on GitHub and cloned a repository with a large number of stars. https://github.com/nezhar/wordpress-docker-compose To build the environment, edit the following "docker-compose.yml" file and ".env" file, and then execute. The final file to be executed is listed at the bottom.

wordpress-docker-compose/docker-compose.yml


version: '3'

services:
  wp:
    image: wordpress:latest # https://hub.docker.com/_/wordpress/
    ports:
      - ${IP}:80:80 # change ip if required
    volumes:
      - ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
      - ./wp-app:/var/www/html # Full wordpress project
      #- ./plugin-name/trunk/:/var/www/html/wp-content/plugins/plugin-name # Plugin development
      #- ./theme-name/trunk/:/var/www/html/wp-content/themes/theme-name # Theme development
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: "${DB_NAME}"
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: "${DB_ROOT_PASSWORD}"
    depends_on:
      - db
    links:
      - db

  wpcli:
    image: wordpress:cli
    volumes:
      - ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
      - ./wp-app:/var/www/html
    depends_on:
      - db
      - wp

  pma:
    image: phpmyadmin/phpmyadmin
    environment:
      # https://docs.phpmyadmin.net/en/latest/setup.html#docker-environment-variables
      PMA_HOST: db
      PMA_PORT: 3306
      MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
    ports:
      - ${IP}:8080:80
    links:
      - db:db

  db:
    image: mysql:latest # https://hub.docker.com/_/mysql/ - or mariadb https://hub.docker.com/_/mariadb
    ports:
      - ${IP}:3306:3306 # change ip if required
    command: [
        '--default_authentication_plugin=mysql_native_password',
        '--character-set-server=utf8mb4',
        '--collation-server=utf8mb4_unicode_ci'
    ]
    volumes:
      - ./wp-data:/docker-entrypoint-initdb.d
      - db_data:/var/lib/mysql
    environment:
      MYSQL_DATABASE: "${DB_NAME}"
      MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"

volumes:
  db_data:

wordpress-docker-compose/.env


IP=127.0.0.1
DB_ROOT_PASSWORD=password
DB_NAME=wordpress

procedure

Repository clone

First, SSH into your EC2 instance to clone the repository.

git clone  https://github.com/nezhar/wordpress-docker-compose.git

Unedited file

You can see that the "wordpress-docker-compose" directory is created, so edit the file "docker-compose.yml" in it. If you execute it without editing it, the loopback address "IP = 127.0.0.1" is set and you cannot see it even if you access it as it is. Therefore, delete "$ {IP}:" as shown below. There are three places to delete the "web", "pma", and "db" services.

docker-compose.yml


#Change before
ports:
      - ${IP}:80:80
        ︙
      - ${IP}:8080:80
        ︙
      - ${IP}:3306:3306

#After change
ports:
      - 80:80
        ︙
      - 8080:80
        ︙
      - 3306:3306

Also, add PMA_USER and PMA_PASSWORD to omit the login input of phpMyAdmin.

wordpress-docker-compose/docker-compose.yml


PMA_USER: root
PMA_PASSWORD: "${DB_ROOT_PASSWORD}"

Add the following to the "pma" and "db" services.

wordpress-docker-compose/docker-compose.yml


MYSQL_USER: "${DB_USER}"
MYSQL_PASSWORD: "${DB_PASSWORD}"

Add the following to the ".env" file.

wordpress-docker-compose/.env


DB_USER=wordpress
DB_PASSWORD=wordpress

Edited file

The edited "docker-compose.yml" and ".env" files are as follows.

wordpress-docker-compose/docker-compose.yml


version: '3'

services:
  wp:
    image: wordpress:latest # https://hub.docker.com/_/wordpress/
    ports:
      - 80:80 # change ip if required
      #- ${IP}:80:80 # change ip if required
    volumes:
      - ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
      - ./wp-app:/var/www/html # Full wordpress project
      #- ./plugin-name/trunk/:/var/www/html/wp-content/plugins/plugin-name # Plugin development
      #- ./theme-name/trunk/:/var/www/html/wp-content/themes/theme-name # Theme development
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: "${DB_NAME}"
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: "${DB_ROOT_PASSWORD}"
    depends_on:
      - db
    links:
      - db

  wpcli:
    image: wordpress:cli
    volumes:
      - ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
      - ./wp-app:/var/www/html
    depends_on:
      - db
      - wp

  pma:
    image: phpmyadmin/phpmyadmin
    environment:
      # https://docs.phpmyadmin.net/en/latest/setup.html#docker-environment-variables
      PMA_HOST: db
      PMA_PORT: 3306
      PMA_USER: root #add
      PMA_PASSWORD: "${DB_ROOT_PASSWORD}" #add
      MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
      MYSQL_USER: "${DB_USER}" #add
      MYSQL_PASSWORD: "${DB_PASSWORD}" #add
    ports:
      - 8080:80
      #- ${IP}:8080:80
    links:
      - db:db

  db:
    image: mysql:latest # https://hub.docker.com/_/mysql/ - or mariadb https://hub.docker.com/_/mariadb
    ports:
      - 3306:3306 # change ip if required
      #- ${IP}:3306:3306 # change ip if required
    command: [
        '--default_authentication_plugin=mysql_native_password',
        '--character-set-server=utf8mb4',
        '--collation-server=utf8mb4_unicode_ci'
    ]
    volumes:
      - ./wp-data:/docker-entrypoint-initdb.d
      - db_data:/var/lib/mysql
    environment:
      MYSQL_DATABASE: "${DB_NAME}"
      MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
      MYSQL_USER: "${DB_USER}" #add
      MYSQL_PASSWORD: "${DB_PASSWORD}" #add
volumes:
  db_data:

wordpress-docker-compose/.env


IP=127.0.0.1
DB_ROOT_PASSWORD=password
DB_NAME=wordpress
DB_USER=wordpress
DB_PASSWORD=wordpress

Container startup

Start the container. If you edit the file again after executing the following command, execute the following command again.

docker-compose up -d

Start WordPress

Please access the public DNS. Hopefully you should see WordPress. (Example) http://ec2-・ ・ ・ ・ ・ ・ .ap-northeast-1.compute.amazonaws.com/

Also, access phpMyAdmin by adding ": 8080" after the url as shown below. (Example) http://ec2-・ ・ ・ ・ ・ ・ .ap-northeast-1.compute.amazonaws.com:8080

reference

[Reference] https://github.com/nezhar/wordpress-docker-compose [Reference] https://docs.docker.com/compose/wordpress/?_fsi=5qcfFUpc

Recommended Posts

Building an environment for WordPress, MySQL and phpMyAdmin with Docker Compose on EC2
WordPress with Docker Compose on CentOS 8
Building an environment for creating apps with Rails and Vue
Measures for permissions when building MySQL with Docker on WSL2
Building Rails 6 and PostgreSQL environment with Docker
Create Rails 6 + MySQL environment with Docker compose
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Laravel + MySQL + phpMyadmin environment construction with Docker
Build a development environment for Django + MySQL + nginx with Docker Compose
Build an environment with Docker on AWS
Notes on building Rails6 / PostgreSQL with Docker Compose
Build WordPress environment with Docker (Local) and AWS (Production)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (5)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (6)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (3)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (2)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (1)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (4)
Easy environment construction of MySQL and Redis with Docker and Alfred
Building a Docker environment on EC2 (ArgumentError: Missing `secret_key_base`, Mysql2 :: Error :: ConnectionError: Access denied for user'root'@ '172.18.0.4' (using password: NO) solution)
Rails + MySQL environment construction with Docker
Environment construction with Docker for beginners
Build Rails environment with Docker Compose
[Environment construction with Docker] Rails 6 & MySQL 8
Building a haskell environment with Docker + VS Code on Windows 10 Home
"Rails 6 x MySQL 8" Docker environment construction procedure for sharing with teams
I built a rails environment with docker and mysql, but I got stuck
Let's install Docker on Windows 10 and create a verification environment for CentOS 8!
[Docker] Building an environment to use Hugo
Starting with installing Docker on EC2 and running Yellowfin in a container
Edit Mysql with commands in Docker environment
Create a MySQL environment with Docker from 0-> 1
Build a web application development environment that uses Java, MySQL, and Redis with Docker CE for Windows
[Copy and paste] Build a Laravel development environment with Docker Compose Part 2
Build a Wordpress development environment with Docker
Allow image posting with [Docker + WordPress + MySQL]
[Copy and paste] Build a Laravel development environment with Docker Compose Participation
Prepare the environment for CUDA, Nvida-Driver, and cuDNN on an Ubuntu 18.04 PC equipped with Geforce RTX2080 SUPER.
Build an Ultra96v2 development environment on Docker 1
Complete roadmap for building environment up to Docker + rails6 + MySQL + bootstrap, jquery
[Error resolution] Occurs when trying to build an environment for spring with docker
Create an ARM-cpu environment with qemu on mac and run java [Result → Failure]
[Workshop for beginners] Let's write an E2E test with Cloud9 + Docker Compose + Cypress!
A memorandum when building an environment with Ruby3.0 x Rails6.1 x Docker x CentOS Stream
Run Docker environment Rails MySQL on Heroku. devise and hiding the twitter API
How to build an environment of [TypeScript + Vue + Express + MySQL] with Docker ~ Vue edition ~
Environment construction command memo with Docker on AWS
Building a Ruby environment for classes on Mac
Build a WordPress development environment quickly with Docker
Rails6 [API mode] + MySQL5.7 environment construction with Docker
I installed Docker on EC2 and started it
Building OpenPose (Pytorch_Realtime_Multi-Person_Pose_Estimation) environment on Docker: training part
Prepare a scraping environment with Docker and Java
[Rails] Building an environment for developing web applications
React + Django + Nginx + MySQL environment construction with Docker
I tried installing docker on an EC2 instance
[Rails] How to build an environment with Docker
[First team development ②] Build an environment with Docker
Wordpress local environment construction & development procedure with Docker
Create an environment for Tomcat and Postgres on a Chromebook without using developer mode
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant