为什么官方Docker镜像的php-fpm对我不起作用?

weixin_38051760 2019-09-12 11:43:17
我尝试从php运行一个新容器:fpm: docker run –name fpmtest -d -p 80:9000 php:fpm 默认情况下,它在其Dockerfile中公开端口9000. 然后我登录到容器并创建index.html文件: $docker exec -i -t fpmtest bash root@2fb39dd6a40b:/var/www/html# echo "Hello, World!" > index.html 在容器内部,我尝试使用curl获取此内容: # curl localhost:9000 curl: (56) Recv failure: Connection reset by peer 在容器外面我得到另一个错误: $curl localhost curl: (52) Empty reply from server
...全文
186 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38092709 2019-09-12
  • 打赏
  • 举报
回复
我想你误解了那个容器的用途.没有Web服务器正在侦听. 容器的端口9000是Web服务器可以用来与php解释器通信的套接字. 在您链接的git存储库的the parent folder中,有另一个运行apache容器的文件夹,它似乎与fpm容器一起工作. 我想在你的情况下你应该这样做: docker run -it --rm --name my-apache-php-app -v /PATH/TO/WEB-FILES:/var/www/html php:5.6-apache 这是使用php docker镜像的官方文档: https://registry.hub.docker.com/_/php/ 作为一个例子,假设我们想要将php-fpm容器与另一个运行nginx Web服务器的容器一起使用. 首先,使用php文件创建一个目录,例如: mkdir content echo '<?php echo "Hello World!"?>' > content/index.php 然后,创建另一个目录conf.d,并在其中创建一个包含以下内容的default.conf文件: server { server_name localhost; root /var/www/html; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.html; } location ~ \.php${ try_files $uri =404; #fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_pass fpmtestdocker:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 注意fastcgi_pass参数值.那么,在这种情况下,我们首先运行: docker run --name fpmtest -d -p 9000:9000 -v $PWD/content:/var/www/html php:fpm 然后: docker run --name nginxtest -p 80:80 --link fpmtest:fpmtestdocker -v $PWD/content:/var/www/html -v $PWD/conf.d:/etc/nginx/conf.d -d nginx 就是这样.我们可以去http://localhost查看结果. 要考虑到: >两个容器都需要访问相同的/ var / www / html目录.他们共享应用程序文件的路径.> –link fpmtest:fpmtestdocker param,以便从nginx容器中看到fpm容器.然后我们可以添加fastcgi_pass fpmtestdocker:9000; nginx服务器配置中的config指令.

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧