
PHP镜像下载
docker pull php:7.4.8-fpmNginx镜像下载
docker pull nginxMysql镜像下载
docker pull mysql:5.7 验证
docker images结果如图:
创建 ~/nginx/conf/ 配置等目录
mkdir -p ~/nginx/logs ~/nginx/conf创建nginx的配置文件
vim ~/nginx/conf/nginx.conf配置文件如下:
server {
listen 80;
server_name localhost;
location / {
root /webroot/;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /webroot/;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;
include fastcgi_params;
}
}配置文件说明:
在 ~/Documents/code 目录下创建index.php
<?php
phpinfo();
?>运行Mysql容器
docker run -it -d -p8066:3306 -e MYSQL_ROOT_PASSWORD=123456 --name mysql57 -v ~/Documents/code/mysqldata:/usr/local/mysql mysql:5.7运行PHP容器
docker run --name php7 -v ~/Documents/code:/webroot -v ~/php/etc:/usr/local/etc/php/conf.d -d php:7.4.8-fpm运行Nginx容器
docker run --name mynginx -p 80:80 -v ~/Documents/code:/webroot -v ~/nginx/conf:/etc/nginx/conf.d --link php7:php --link mysql57:mysql -d nginx命令说明:
浏览器访问 localhost
vim ~/nginx/conf/nginx.confserver {
listen 80;
server_name mytest.com;
location / {
root /webroot/test/;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /webroot/test/;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /webroot/test/$fastcgi_script_name;
include fastcgi_params;
}
}docker restart mynginxsudo vim /ets/hosts增加
127.0.0.1 mytest.com在~/Documents/code下创建test文件夹,在该文件夹新建一个index.php
<?php
echo "hello world";
?>浏览器访问 mytest.com

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。