docker部署LNMP
1.创建nginx容器和php容器,并挂载共享目录:/opt/html
docker run --name web1 -d -p 80:80 -v /opt/html:/html nginx
docker run --name php-fpm -d -p 9000:9000 -v /opt/html:/www php-fpm:5.6
2.获取配置文件模板
tar zxf nginx-1.18.0.tar.gz
cp nginx-1.18.0/conf/nginx.conf ./
3.编辑配置文件,整合nginx和php容器
vim nginx.conf
server{
......
location / {
root /html; # 网站根目录
index index.php;
}
.....
location ~ \.php$ {
root /www; # php容器读取文件的路径
fastcgi_pass 192.168.189.171:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
.....
}
- 复制修改的nginx配置文件到nginx容器中,更新配置
docker cp nginx.conf web1:/etc/nginx/nginx.conf - 重启nginx容器
docker restart web1 - 创建测试页面
cd /opt/html
vim index.php <?php phpinfo(); ?> - 创建mysql容器
docker run --name mysql -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123 mysql:5.6