PHP-FPM
is running locally on my Ubuntu 20.04 installation, configured to listen on a socket:
/etc/php/7.4/fpm/pool.d/www.conf:
[www]
user = www-data
group = www-data
listen = /run/php/php7.4-fpm.sock
listen.owner = www-data
listen.group = www-data
;listen.mode = 0660
;listen.acl_users =
;listen.acl_groups =
I can start a Docker container and communicate with PHP-FPM
by sharing the socket file through a bind mount volume:
$ docker run --rm -it \
-v "/etc/passwd:/etc/passwd:ro" \
-v "/etc/group:/etc/group:ro" \
-v "/run/php/php7.4-fpm.sock:/run/php-fpm/www.sock" \
alpine:latest
/ # apk add --no-cache fcgi
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/1) Installing fcgi (2.4.2-r0)
Executing busybox-1.31.1-r16.trigger
OK: 6 MiB in 15 packages
/ # ls -lah /run/php-fpm/www.sock
srw-rw---- 1 www-data www-data 0 Oct 30 21:25 /run/php-fpm/www.sock
/ # REQUEST_METHOD=GET SCRIPT_FILENAME=index.php cgi-fcgi -bind -connect /run/php-fpm/www.sock
Primary script unknownStatus: 404 Not Found
Content-type: text/html; charset=UTF-8
File not found.
Now if I restart PHP-FPM
on the host while the container is still running:
$ sudo systemctl restart php7.4-fpm.service
$ sudo tail -n 6 /var/log/php7.4-fpm.log
[30-Oct-2020 18:25:36] NOTICE: systemd monitor interval set to 10000ms
[30-Oct-2020 18:28:47] NOTICE: Terminating ...
[30-Oct-2020 18:28:47] NOTICE: exiting, bye-bye!
[30-Oct-2020 18:28:47] NOTICE: fpm is running, pid 67860
[30-Oct-2020 18:28:47] NOTICE: ready to handle connections
[30-Oct-2020 18:28:47] NOTICE: systemd monitor interval set to 10000ms
I am no longer able to connect to the socket from the Docker container:
/ # REQUEST_METHOD=GET SCRIPT_FILENAME=index.php cgi-fcgi -bind -connect /run/php-fpm/www.sock
Could not connect to /run/php-fpm/www.sock
If the container is re-started, it works again.
So I imagine that the problem is related to how sockets shared in bind mounts work, but it could also be on PHP-FPM
, I have no idea on how to "fix" this.