How and where to configure pm.max_children for php-fpm with Docker?

In a Web application with Nginx and PHP-FPM, I've noticed moments of slowness and analyzing the logs, I found this message, which appears from time to time:

[19-Nov-2017 19:24:09] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it

After some reseach, I increased the values in the php.ini configuration file, stopped and removed the php container and rebuild it, for the setting set to a file on a volume had effect.

Analyzing the configuration file inside the container, it's with the new values that I set, however, the error message about pm.max_children (5) continues to appear.

Here is my docker-compose.yml

version: '2'


        build: ./nginx
            - "80:80"
            - "443:443"

            - ../src:/src
            - ./nginx/conf.d:/etc/nginx/conf.d
            - ./nginx/nginx.conf:/etc/nginx/nginx.conf
            - /etc/letsencrypt:/etc/letsencrypt

        build: ./php
            - ../src:/src
            - ./php/config/php.ini:/usr/local/etc/php/php.ini

Here is a snippet of the ./php/config/php.ini:

pm = dynamic
pm.max_children = 40
pm.start_servers = 15
pm.min_spare_servers = 15
pm.max_spare_servers = 25

And, if I run:

$ docker exec -it docker_pi_php_1 cat /usr/local/etc/php/php.ini

I see the same values on the snippet above.

The path to the configuration file inside the container is correct, I ran:

$ php --ini 

inside the container and the path is in the list of loaded configuration files.

I've fried my brain trying to get around this problem, but so far I haven't succeeded.

Any ideas?

I may be wrong, but assuming you're using the official PHP images those pm settings should be placed inside the /usr/local/etc/php-fpm.d/ directory inside a file with conf extension. According to PHP docs, those settings are FPM related and although they use php.ini syntax, they should be placed in a different file, so I believe that your pm settings are being ignored. This Dockerfile in PHP helped me to find out where are those conf files supposed to be.

I'd check if you have a /usr/local/etc/php-fpm.d/www.conf file inside your container where that max_children is now set to 5. If that is so I guess you could modify your Dockerfile to copy a new www.conf file that sets a higher value for pm.max_children.

I find clearer to overwrite specific settings using the file that ships with the official php:7.3-fpm image: /usr/local/etc/php-fpm.d/zz-docker.conf

This file ends with something like:

listen = 9000

So we can just append it with exactly what we need to set for the www pool.

For instance:

# SETUP PHP-FPM CONFIG SETTINGS (max_children / max_requests)
RUN echo 'pm.max_children = 15' >> /usr/local/etc/php-fpm.d/zz-docker.conf && \
    echo 'pm.max_requests = 500' >> /usr/local/etc/php-fpm.d/zz-docker.conf

I think it's simpler and clearer.