Docker部署LNMP完整教程 (2)

然后重新启动容器:

$ docker stop php-fpm $ docker rm php-fpm $ docker run --name php-fpm --link mysql:mysql -v /Users/xiaohao/Desktop/www/:/usr/share/nginx/html -v /Users/xiaohao/Desktop/www/config/www.conf:/usr/local/etc/php-fpm.d/www.conf -v /Users/xiaohao/Desktop/www/config/php.ini:/usr/local/etc/php-7.3.0/php.ini -d php:fpm

这样PHP-FPM的容器就部署完成了。注意,要保证配置文件 php.ini 和 没有错误,否则会无法启动容器。

5 让Nginx容器支持FPM

打开 nginx 的配置文件,修改内容如下:

server { listen 80; server_name _; root /usr/share/nginx/html; index index.php index.html index.htm; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { #root /usr/share/nginx/html; #index index.php index.html index.htm; try_files $uri $uri/ =404; } error_page 404 /404.html; location = /40x.html { root /user/share/nginx/html; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass ; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_pass php-fpm:9000; fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } }

然后启动 nginx:

$docker stop nginx $docker rm nginx $ docker run --name nginx -p 80:80 --link php-fpm -v /Users/xiaohao/Desktop/www:/usr/share/nginx/html -v /Users/xiaohao/Desktop/www/config/default.conf:/etc/nginx/conf.d/default.conf -d nginx

在宿主机下的 /Users/xiaohao/Desktop/www下创建 index.php 文件,内容:

<?php phpinfo(); ?>

在浏览器上访问 或者本机ip地址/或者127.0.0.1,刷新一下就可以看到新的内容了。

参考资料:

https://www.awaimai.com/728.html 参考这篇blog的,但是原作者写的有bug,我帮他改写了

docker-lnmp: Dockerfiles for deploying applications of apporz.com anywhere](https://github.com/micooz/docker-lnmp)

How To Run Nginx in a Docker Container on Ubuntu 14.04

Legacy container links

How To Install Docker on CentOS 6

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpfpzf.html