一、docker 分布式 lnmp 镜像制作
1、运行Nginx、MySQL、PHP容器
#关闭防火墙及核心防护
systemctl disable firewalld
systemctl stop firewalld
setenforce0
#查看3306、80及9000端口是否被占用
ss-natp| grep3306
ss-natp| grep80
ss-natp| grep9000
#创建自定义网络
docker network create-d bridge--subnet172.168.184.0/24--gateway172.168.184.1 lnmp
#运行Nginx容器
docker run-itd--name nginx--network lnmp-p80:80--ip172.168.184.10 nginx:1.12.0
#运行MySQL容器
docker run-itd--name mysql--network lnmp-p3306:3306--ip172.168.184.20-e MYSQL_ROOT_PASSWORD=010230 mysql:5.7
#运行PHP容器
docker run-itd--name phpfpm--network lnmp-p9000:9000--ip172.168.184.30 php:7.1-fpm



2、修改Nginx配置文件和PHP文件
docker exec-it nginx/bin/bash
echo-e "server{
listen80;
server_name localhost;
location/{
root/usr/share/nginx/html;
index index.html index.htmi index.php;}
error_page500502503504/50x.html;
location=/50x.html{
root/usr/share/nginx/html;}
location~ \.php${
root/usr/share/nginx/html;
fastcgi_pass172.168.184.30:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;}}">/etc/nginx/conf.d/default.conf
nginx-s reload
docker exec-it phpfpm/bin/bash
mkdir-p/usr/share/nginx/html
echo "<?phpphpinfo();?>">/usr/share/nginx/html/index.php


4、进行测试
虚拟机输入localhost/index.php

本机输入 192.168.184.70/index.php (我虚拟机地址是192.168.184.70)
