wordpress

Wordpress 本地容器运行方式

1.docker启动mysql 8

1.1启动mysql容器

docker run --name wordpress-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d --security-opt seccomp=unconfined mysql:8.0.20 

–security-opt seccomp=unconfined 参数是因为wordpress容器运行时,会报错,所以加了该参数,详情可参考 https://blog.csdn.net/CrazyQiQi/article/details/126260438

1.2设置mysql远程访问

root@iZuf64s86ucw3ichp92qj5Z:~# docker exec -it 5cd7063a7553 /bin/bash
root@5cd7063a7553:/# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.20 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host      | user             | plugin                | authentication_string                                                  |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| %         | root             | caching_sha2_password | $A$005$?\"7{aQvf
                                                                         @H-ut6G9wl0CZjPDKseRNY8GBE1lZTEDDsnK6QNcM8Tm8eg7 |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | caching_sha2_password | $A$005$~e>*[&aJ~v,N
#{cI5K5/4B/3Z7fX7hKk5vE05YW79kbk/WWqI7cbP63d7 |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.00 sec)
只有这样设置后,外部才能连接该数据库
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; 
Query OK, 0 rows affected (0.00 sec)

mysql> use mysql;
Database changed
mysql> select host,user,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host      | user             | plugin                | authentication_string                                                  |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| %         | root             | mysql_native_password | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9                              |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | caching_sha2_password | $A$005$~e>*[&aJ~v,N
#{cI5K5/4B/3Z7fX7hKk5vE05YW79kbk/WWqI7cbP63d7 |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.00 sec)

mysql> 

2.docker启动wordpress

-v 把wp-content挂载出来,可确保容器挂了后内容不会丢失

docker run --name wordpress -v /Users/wulili/Desktop/mycode/wp-content:/var/www/html/wp-content  -e WORDPRESS_DB_HOST=127.0.0.1:3307 -p 9099:80 -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_NAME=wordpress -e WORDPRESS_DB_PASSWORD=123456 -d wordpress:6.3.1

运行成功后,本地可直接http://127.0.0.1:9099/访问

留言

您的邮箱地址不会被公开。 必填项已用 * 标注

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。