Why is php-fpm from the official Docker image not working for me?
I am trying to start a new container from php:fpm
:
docker run --name fpmtest -d -p 80:9000 php:fpm
By default, it provides port 9000 in the Dockerfile .
Then I go into the container and create an index.html file:
$ docker exec -i -t fpmtest bash
root@2fb39dd6a40b:/var/www/html# echo "Hello, World!" > index.html
And inside the container, I am trying to get this content with curl
:
# curl localhost:9000
curl: (56) Recv failure: Connection reset by peer
Outside of the container, I get another error:
$ curl localhost
curl: (52) Empty reply from server
source to share
I think you misunderstood the purpose of this container. No web server listening.
Port 9000 of the container is a socket that the web server can use to communicate with the php interpreter.
In the parent folder of the git repository you linked, there is another folder that starts the apache container, it looks like there to work with the fpm container.
I think in your case you should do:
docker run -it --rm --name my-apache-php-app -v /PATH/TO/WEB-FILES:/var/www/html php:5.6-apache
Here is the official documentation for working with php docker images:
https://registry.hub.docker.com/_/php/
As an example, let's say we want to use this php-fpm container with another container running the nginx web server .
First create a directory with php files, for example:
mkdir content
echo '<?php echo "Hello World!"?>' > content/index.php
Then create another directory conf.d
and inside it create a file default.conf
with this content:
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;
}
}
Pay attention to the value of the fastcgi_pass parameter. Well, in this scenario, we run first:
docker run --name fpmtest -d -p 9000:9000 -v $PWD/content:/var/www/html php:fpm
And then:
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
What is it. We can go to http: // localhost and see the results.
Take into account:
- Both containers need access to the same / var / www / html directory. They share paths to application files.
-
--link fpmtest:fpmtestdocker
so that the fpm container is visible from the nginx container. Then we can add thefastcgi_pass fpmtestdocker:9000;
config directive to the nginx server config.
source to share
This is untested but loosely based on md5's excellent gist . To use this image with nginx, your Dockerfile for this image looks like this:
Dockerfile
FROM nginx:1.7
COPY php-fpm.conf /etc/nginx.conf.d/default.conf
The nginx.conf example you copy might look like this.
PHP-fpm.conf
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass fpmtest:9000;
fastcgi_index index.php;
}
}
Note. fastcgi_pass refers to your container name (fpmtest).
source to share