docker筆記之搭建LNMP平臺(wordpress)
阿新 • • 發佈:2018-11-13
建立mysql資料庫容器
[[email protected] web]# docker run -itd --name lnmp_mysql -p 3308:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql --character-set-server=utf8 [[email protected] web]# docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e917f4613326 mysql "docker-entrypoint.s…" 11 seconds ago Up 9 seconds 33060/tcp, 0.0.0.0:3308->3306/tcp lnmp_mysql
建立相關wp庫
[[email protected] ~]# docker exec lnmp_mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "create database wp"' mysql: [Warning] Using a password on the command line interface can be insecure. [[email protected] ~]# [[email protected] ~]# docker exec lnmp_mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "show databases"' mysql: [Warning] Using a password on the command line interface can be insecure. Database information_schema mysql performance_schema sys wp
建立PHP依賴容器
[[email protected] ~]# docker run -itd --name lnmp_web --link lnmp_mysql:db -p 88:80 -v /container_data/web:/var/www/html richarvey/nginx-php-fpm [[email protected] ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4af014266847 richarvey/nginx-php-fpm "docker-php-entrypoi…" 20 seconds ago Up 19 seconds 443/tcp, 9000/tcp, 0.0.0.0:88->80/tcp lnmp_web 94ffdd912847 mysql "docker-entrypoint.s…" 8 minutes ago Up 8 minutes 33060/tcp, 0.0.0.0:3308->3306/tcp lnmp_mysql
測試PHP環境
[[email protected] ~]# cd /container_data/web/
▽[email protected] web]# ls
index.php
[[email protected] web]# vim index.php
<?php
phpinfo()
?>
進入網頁開啟:10.0.0205:88 --前面是我本機的外網ip,埠號是容器中的印射埠
一直在轉就是不出現PHPinfo資訊
重新配置了一下iptables,重啟了一下容器就好了
[[email protected] web]# iptables -t nat -vnL
[[email protected] web]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[[email protected] web]# docker start lnmp_mysql
lnmp_mysql
[[email protected] web]# docker start lnmp_web
lnmp_web
然後就是下載安裝WordPress了,就不細說了
[[email protected] web]# ls
index.php wordpress-4.7.2-zh_CN.tar.gz
[[email protected] web]# tar xf wordpress-4.7.2-zh_CN.tar.gz
[[email protected] web]# mv wordpress
wordpress/ wordpress-4.7.2-zh_CN.tar.gz
[[email protected] web]# mv wordpress/* ./
資料庫容器主機
[[email protected] web]# docker exec lnmp_web cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 db 94ffdd912847 lnmp_mysql
172.17.0.3 4af014266847