【Dockerfile镜像实战】构建LNMP环境并运行Wordpress网站平台
Nginx部署
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
cd /opt
mkdir nginx
cd nginx
vim Dockerfile
vim nginx.conf
cd /opt/nginx
rz -E //将nginx的安装包导入进来
mkdir html
cd html
rz -E //将wordpress的安装包导入进来
tar xf wordpress-4.9.4-zh_CN.tar.gz //解压文件
rm -rf wordpress-4.9.4-zh_CN.tar.gz //删除压缩包
[root@localhost nginx]
[root@localhost nginx]
docker run -d --name nginx -p 80:80 -v /opt/nginx/html:/usr/local/nginx/html -v /opt/nginx/nginx.conf:/usr/local/nginx/conf/nginx.conf --net lnmpnetwork --ip 172.18.0.10 nginx:lnmp
docker ps -a
cd /opt/nginx/html
vim index.html
//新建一个测试网页,查看nginx是否能正常运行
[root@localhost nginx]
[root@d94d0066c01a /]
[root@d94d0066c01a /]
[root@d94d0066c01a html]
[root@d94d0066c01a html]
wordpress
MySQL部署
[root@localhost nginx]
[root@localhost opt]
[root@localhost opt]
containerd nginx rh
[root@localhost opt]
[root@localhost opt]
[root@localhost opt]
[root@localhost opt]
containerd mysql nginx php rh
[root@localhost opt]
[root@localhost opt]
[root@localhost mysql]
[root@localhost mysql]
[root@localhost mysql]
[root@localhost mysql]
rz waiting to receive.
[root@localhost mysql]
[root@localhost mysql]
[root@localhost mysql]
[root@localhost mysql]
Dockerfile mysql-boost-5.7.41.tar.gz
[root@localhost mysql]
[root@localhost mysql]
[root@localhost mysql]
[root@localhost docker]
13f2bb048679a6d4042f5f235e794305ca6e8c2912d8b13b8b8d891c0911a34f
[root@localhost docker]
[root@localhost docker]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
13f2bb048679 mysql:lnmp "/usr/local/mysql/bi…" 17 seconds ago Up 10 seconds 3306/tcp mysql
d94d0066c01a nginx:lnmp "/usr/local/nginx/sb…" 2 hours ago Up 46 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp nginx
[root@localhost docker]
[root@13f2bb048679 mysql]
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> quit;
Bye
[root@13f2bb048679 mysql]
[root@13f2bb048679 mysql]
[root@13f2bb048679 mysql]
PHP部署
[root@localhost mysql]
[root@localhost mysql]
[root@localhost php]
[root@localhost php]
[root@localhost php]
[root@localhost php]
rz waiting to receive.
[root@localhost php]
[root@localhost php]
php-7.1.10.tar.bz2
[root@localhost php]
[root@localhost php]
[root@localhost php]
[root@localhost php]
[root@localhost php]
[root@localhost php]
[root@localhost php]
[root@localhost php]
[root@localhost php]
[root@localhost php]
[root@localhost php]
[root@localhost php]
REPOSITORY TAG IMAGE ID CREATED SIZE
php lnmp f969ee0fe328 2 minutes ago 421MB
mysql lnmp 03aa4c425566 3 hours ago 4.24GB
nginx lnmp 01356f501e0c 6 hours ago 208MB
centos 7 eeb6ee3f44bd 2 years ago 204MB
[root@localhost php]
[root@localhost php]
fc67bd7f644ba8b704398db992420fcf80662b50b0a1ab28a9200af6ff73f400
[root@localhost php]
[root@localhost php]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fc67bd7f644b php:lnmp "/usr/local/php/sbin…" 12 seconds ago Up 11 seconds 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp php
13f2bb048679 mysql:lnmp "/usr/local/mysql/bi…" 3 hours ago Up 3 hours 3306/tcp mysql
d94d0066c01a nginx:lnmp "/usr/local/nginx/sb…" 5 hours ago Up 4 hours 0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp nginx
[root@localhost php]
[root@localhost php]
[root@d94d0066c01a /]
[root@d94d0066c01a /]
[root@d94d0066c01a html]
[root@d94d0066c01a html]
total 4
drwxr-xr-x. 5 nobody 65534 4096 Feb 8 2018 wordpress
[root@d94d0066c01a html]
[root@d94d0066c01a html]
[root@d94d0066c01a html]
[root@d94d0066c01a html]
total 4
drwxr-xr-x. 5 nginx nginx 4096 Feb 8 2018 wordpress
[root@d94d0066c01a html]
[root@13f2bb048679 /]
Enter password:
mysql>
mysql> create database wordpress;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| wordpress |
+--------------------+
5 rows in set (0.00 sec)
mysql>
mysql> grant all privileges on wordpress.* to 'wordpress'@'%' identified by 'admin123';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> grant all privileges on *.* to 'root'@'%' identified by 'admin123';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
浏览器访问:
http://192.168.190.120/wordpress/index.php