使用EC2进行Docker Compose的配置,建立WordPress、MySQL和phpMyAdmin的环境
总结
通过在AWS的EC2上使用Docker Compose,我已经创建了WordPress、MySQL和phpMyAdmin的环境,为了方便以后查看,我将其记录下来。省略了Docker的安装步骤等。
由于还未写出EC2实例连接的步骤,我会在另外的帖子中发布。
我在GitHub中搜索了”docker wordpress”,并克隆了星星数较多的存储库。
https://github.com/nezhar/wordpress-docker-compose
在进行环境配置时,我将编辑以下的”docker-compose.yml”文件和”.env”文件,然后进行执行。最终要执行的文件在底部附有说明。
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:
IP=127.0.0.1
DB_ROOT_PASSWORD=password
DB_NAME=wordpress
步骤
克隆存储库
首先,通过SSH连接到EC2实例,并克隆存储库。
git clone https://github.com/nezhar/wordpress-docker-compose.git
编辑前的文件
确认”wordpress-docker-compose”文件夹已经创建,然后编辑其中的”docker-compose.yml”文件。如果不进行编辑并直接运行,将默认设置回环地址”IP=127.0.0.1″,这样无法访问。因此,需要删除”${IP}:”。要删除的位置分别在”web”、”pma”和”db”服务的三个地方。
#変更前
ports:
- ${IP}:80:80
︙
- ${IP}:8080:80
︙
- ${IP}:3306:3306
#変更後
ports:
- 80:80
︙
- 8080:80
︙
- 3306:3306
另外,为了省略phpMyAdmin的登录输入,我们可以添加PMA_USER和PMA_PASSWORD。
PMA_USER: root
PMA_PASSWORD: "${DB_ROOT_PASSWORD}"
我会在“PMA”和“DB”服务中添加以下内容。
MYSQL_USER: "${DB_USER}"
MYSQL_PASSWORD: "${DB_PASSWORD}"
将以下内容添加到 “.env” 文件中。
DB_USER=wordpress
DB_PASSWORD=wordpress
编辑后的文件 de
以下是編輯完成的 “docker-compose.yml” 文件和 “.env” 文件。
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:
IP=127.0.0.1
DB_ROOT_PASSWORD=password
DB_NAME=wordpress
DB_USER=wordpress
DB_PASSWORD=wordpress
启动容器
启动容器。如果在执行下面的命令后重新编辑文件,请再次执行下面的命令。
docker-compose up -d
开始使用WordPress
请访问公共DNS。如果一切顺利,您应该能看到WordPress的界面。
(例如)http://ec2-・・・・・・.ap-northeast-1.compute.amazonaws.com/
另外,请在URL后面加上”:8080″,访问phpMyAdmin,示例如下:http://ec2-・・・・・・.ap-northeast-1.compute.amazonaws.com:8080
请提供更多的上下文信息以便为您提供准确的翻译。
[参考]这是一个链接:https://github.com/nezhar/wordpress-docker-compose
[参考]这是另一个链接:https://docs.docker.com/compose/wordpress/?_fsi=5qcfFUpc