我尝试从以下位置运行新容器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
Run Code Online (Sandbox Code Playgroud)
在容器内部,我尝试使用以下内容获取此内容curl:
# curl localhost:9000
curl: (56) Recv failure: Connection reset by peer
Run Code Online (Sandbox Code Playgroud)
在容器外面我得到另一个错误:
$ curl localhost
curl: (52) Empty reply from server
Run Code Online (Sandbox Code Playgroud)
我想你误解了那个容器的用途.没有Web服务器正在侦听.
容器的端口9000是Web服务器可以用来与php解释器通信的套接字.
在您链接的git存储库的父文件夹中,有另一个文件夹运行一个apache容器,它似乎与fpm容器一起工作.
我想在你的情况下你应该这样做:
docker run -it --rm --name my-apache-php-app -v /PATH/TO/WEB-FILES:/var/www/html php:5.6-apache
Run Code Online (Sandbox Code Playgroud)
这是使用php docker镜像的官方文档:
https://registry.hub.docker.com/_/php/
作为一个例子,假设我们想要将php-fpm容器与另一个运行nginx Web服务器的容器一起使用.
首先,使用php文件创建一个目录,例如:
mkdir content
echo '<?php echo "Hello World!"?>' > content/index.php
Run Code Online (Sandbox Code Playgroud)
然后,创建另一个目录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;
}
}
Run Code Online (Sandbox Code Playgroud)
注意fastcgi_pass参数值.那么,在这种情况下,我们首先运行:
docker run --name fpmtest -d -p 9000:9000 -v $PWD/content:/var/www/html php:fpm
Run Code Online (Sandbox Code Playgroud)
然后:
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
Run Code Online (Sandbox Code Playgroud)
就是这样.我们可以访问http:// localhost并查看结果.
要考虑到:
--link fpmtest:fpmtestdockerparam,以便从nginx容器中看到fpm容器.然后我们可以fastcgi_pass fpmtestdocker:9000;在nginx服务器配置中添加config指令.| 归档时间: |
|
| 查看次数: |
2881 次 |
| 最近记录: |