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
First, SSH into your EC2 instance to clone the repository.
git clone https://github.com/nezhar/wordpress-docker-compose.git
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
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
Start the container. If you edit the file again after executing the following command, execute the following command again.
docker-compose up -d
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] https://github.com/nezhar/wordpress-docker-compose [Reference] https://docs.docker.com/compose/wordpress/?_fsi=5qcfFUpc
Recommended Posts