6

I'm trying to get php-fpm set up on a Docker image.

Here's the service in my docker-compose.yml:

wordpress-service:
  build:
    context: .
    dockerfile: Dockerfile-wordpress
  image: riffsy-web-wordpress:latest
  restart: always
  links:
   - wordpress-mysql
  depends_on:
   - wordpress-mysql
  expose:
    - "8000"
  environment:
   - DB_NAME=wordpress
   - DB_USER=wordpress
   - DB_PASSWORD=password123
   - DB_HOST=wordpress-mysql
   - DB_PORT=3306
  ports:
   - "8000:8000"

Docker image uses this command:

CMD php-fpm7.0 --fpm-config /etc/php-fpm.conf

Here's my php-fpm conf:

[global]

error_log = /dev/stderr
log_level = debug
daemonize = no

[www]
listen = 8000
listen.allowed_clients = 127.0.0.1
user = www-data
group = www-data
pm = dynamic
pm.max_children = 6
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 4
pm.max_requests = 500
request_terminate_timeout = 120s
catch_workers_output = yes

I set listen.allowed_clients = 127.0.0.1 because otherwise I got connection refused messages; eventually I'll need php-fpm to accept connections from any IP, because I don't know what IP my Nginx image will have, and it doesn't matter since my php-fpm image won't be publicly connected to the internet.

I ran docker exec to login to the running image and ran wget to test out the server:

root@428d78fd58df:/srv# wget 127.0.0.1:8000                           
--2016-09-12 07:55:13--  http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.

--2016-09-12 07:55:14--  (try: 2)  http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.

--2016-09-12 07:55:16--  (try: 3)  http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.

^C

The console shows no output other than:

wordpress-service_1  | [12-Sep-2016 08:01:09.757039] DEBUG: pid 5, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 0 active children, 2 spare children, 2 running children. Spawning rate 1
Seán Hayes
  • 4,060
  • 4
  • 33
  • 48
  • 1
    The problem is that `listen.allowed_clients = 127.0.0.1` needs to be set to allow any IP to connect to it. The documentation says that if its blank then it will accept all connections. This does NOT seem to be the case in a docker environment. I've tried commenting this line out and setting `listen.allowed_clients =` neither worked for me. It will only accept connections to IPs you specify. Which you would not know until after the container is running. – b01 Dec 01 '17 at 17:46

1 Answers1

21

The problem is that php-fpm doesn't use the http protocol, it uses fastcgi. The only way to connect with it was by setting up Nginx to use fastcgi.

Seán Hayes
  • 4,060
  • 4
  • 33
  • 48
  • Took me hours to finally see this. Thanks – M at Jan 13 '22 at 20:38
  • Hmm, in my case it IS set up for fastcgi and still getting reset by peer. No doubt for other reasons... will keep looking. – Joshua Eric Turcotte May 04 '22 at 20:17
  • @JoshuaEricTurcotte hi, have you found the solution for this? – Orkhan M. Sep 09 '22 at 10:29
  • Took me a significant amount of time to eventually stumbled upon this invaluable information, I was trying to get the content using the http which is dumb after seeing this lol.. Worked good when I used nginx. Thanks buddy.. – 4hbane Jun 16 '23 at 22:01