docker快速搭建lnmp网站架构 及wordpress博客平台

docker network create lnmp

这里采用mysql5.7版本,加上参数–restart always 保证容器在主机开机时能自启动
docker run -itd –restart always –name lnmp_mysql –net lnmp -p 3306:3306 –mount src=mysql-vol,dst=/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=wordpress mysql:5.7 –character-set-server=utf8
mysql-vol卷会自动创建。
[root@localhost volumes]# pwd
/var/lib/docker/volumes
[root@localhost volumes]# docker volume ls
DRIVER VOLUME NAME
local mysql-vol
local rancher-agent-state
local rancher-cni
local rancher-cni-driver
[root@localhost volumes]# docker volume inspect mysql-vol
[
{
"CreatedAt": "2019-08-18T11:52:35+08:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/mysql-vol/_data",
"Name": "mysql-vol",
"Options": null,
"Scope": "local"
}
]
创建一个卷 例如docker volume create nginx-vol

容器创建后就会创建数据库wordpress
进入mysql容器,docker exec -it lnmp_mysql /bin/bash
进入数据库 mysql –uroot –p123456
创建普通用户
grant all on wordpress.* to wordpress@'%' identified by ‘123456’;
flush privileges;
mysql> select user,host from mysql.user;
+—————+———–+
| user | host |
+—————+———–+
| root | % |
| wordpress | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+—————+———–+
5 rows in set (0.01 sec)

mysql>

也可以不用进容器操作 docker exec lnmp_mysql bash -c 'exec mysql -uroot -p123456 -e "grant all on wordpress.* to wordpress@'%' identified by ‘123456’;"'

docker run -itd –restart always –name lnmp_web –net lnmp -p 88:80 –mount type=bind,src=/lnmp/web,dst=/var/www/html richarvey/nginx-php-fpm
在本地创建/lnmp/web目录,将该目录挂载到容器,实现数据持久化。

原文链接:https://blog.csdn.net/botan7102/article/details/100951288

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享