实验逻辑图
1. 上传并解压mysql,nginx,php-fpm 镜像包
root@localhost lnmp] # ls
mysql5. 7 _utf8. tar. gz nginx. tar. gz php- fpm. tar. gz
[ root@localhost lnmp] # tar xzf mysql5. 7 _utf8. tar. gz
[ root@localhost lnmp] # tar xzf nginx. tar. gz
[ root@localhost lnmp] # tar xzf php- fpm. tar. gz
[ root@localhost lnmp] # ls
mysql5. 7 _utf8. tar mysql5. 7 _utf8. tar. gz nginx. tar nginx. tar. gz php- fpm. tar php- fpm. tar. gz
2. 导入并查看镜像
2.1 导入
[ root@localhost lnmp] # docker load - i mysql5. 7 _utf8. tar
[ root@localhost lnmp] # docker load - i nginx. tar
[ root@localhost lnmp] # docker load - i php- fpm. tar
2.2 查看
[ root@localhost lnmp] # docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 a4cc8ac43867 3 months ago 448 MB
nginx latest 8 cf1bfb43ff5 4 months ago 132 MB
php- fpm 5.6 052 bed1c4ad6 5 months ago 452 MB
[ root@localhost lnmp] #
3. 运行并查看mysql容器
运行
[ root@localhost ~ ] # docker run -- name mysql - d - p 3306 : 3306 - e MYSQL_ROOT_PASSWORD= 123456 mysql: 5.7
f9e8222508e47829e0ecf46850e16741318ab973f06ddfac73119f7b21101a53
查看
[ root@localhost ~ ] # docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f9e8222508e4 mysql: 5.7 "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 0.0 .0 .0 : 3306 - > 3306 / tcp, 33060 / tcp mysql
4. 创建要挂载给nginx和php-fpm的目录
[ root@localhost ~ ] # mkdir / opt/ html
5. 运行nginx容器
[ root@localhost ~ ] # docker run -- name nginx - d - p 80 : 80 - v / opt/ html/ : / usr/ share/ nginx/ html nginx
a54763b9802eb2343c7389fede4792f17f21e4b9bb33710d8c95fc5f9241d6bc
[ root@localhost ~ ] #
6. 运行php-fpm容器
[ root@localhost ~ ] # docker run -- name php- fpm - d - p 9000 : 9000 - v / opt/ html/ : / www php- fpm: 5.6
96 dd18c5e5eaae2f054da6704233ca4e3f42b6d8a8e1561835038e6c399d2e72
[ root@localhost ~ ] #
7.复制并修改nginx源码解压之后的配置文件
[ root@localhost lnmp] # tar xzf nginx- 1.18 .0 . tar. gz
[ root@localhost lnmp] # cp nginx- 1.18 .0 / conf/ nginx. conf . /
[ root@localhost lnmp] # vim nginx. conf
配置文件修改以下部分
43 location / {
44 root / usr/ share/ nginx/ html;
45 index index. php;
46 }
65 location ~ \. php$ {
66 root / www;
67 fastcgi_pass 192.168 .153 .189 : 9000 ;
68 fastcgi_index index. php;
69 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
70 include fastcgi_params;
71 }
8.复制nginx配置文件到容器中并重启容器
8.1 复制
[ root@localhost lnmp] # docker cp nginx. conf nginx: / etc/ nginx/ nginx. conf
8.2 重启nginx容器
[ root@localhost lnmp] # docker restart nginx
nginx
[ root@localhost lnmp] #
9.编写PHP测试页面
[ root@localhost lnmp] # vim / opt/ html/ index. php
[ root@localhost lnmp] # cat / opt/ html/ index. php
< ? php
phpinfo ( ) ;
? >
[ root@localhost lnmp] #
10.浏览器输入宿主机IP访问PHP测试页面