I have a simple docker-compose setup with a nginx proxy and a container running PHP-PM:
version: "3.5"
services:
proxy:
image: nginx
depends_on:
- php_pm
php_pm:
build: .
The Dockerfile for php_pm
is modified from https://github.com/php-pm/php-pm-docker/blob/master/build/Dockerfile-standalone to use PHP 8.1:
FROM composer as composer
ARG version=2.4.0
ARG http_version=dev-master
RUN docker-php-ext-install -j$(nproc) pcntl
RUN mkdir /ppm && cd /ppm && composer require php-pm/php-pm:${version} && composer require php-pm/httpkernel-adapter:${http_version}
FROM php:8.1
RUN apt update && apt install -y git libicu-dev libpng-dev libzip-dev procps xmlsec1 zip zlib1g-dev
RUN docker-php-ext-install -j$(nproc) gd intl mysqli opcache pcntl pdo_mysql zip
EXPOSE 81
COPY --from=composer /ppm /ppm
WORKDIR /var/www
ENTRYPOINT ["/ppm/vendor/bin/ppm", \
"start", \
"--static-directory=public/", \
"--app-env=dev", \
"--port=81", \
"--socket-path=/ppm/run", \
"--pidfile=/ppm/ppm.pid", \
"--debug=1"]
Now if I exec into the php_pm
container and use curl localhost:81
I get a response from PHP-PM (I think that is what the header Server: ReactPHP/1
is).
Now my problem: When I exec into the container proxy
and try to curl the php_pm
container i get this:
curl php_pm:81
curl: (7) Failed to connect to php_pm port 81: Connection refused
Why is PHP-PM answering on port 81 when I'm inside the php_pm
container, but not when I am in the proxy
container? Usually this is not an issue, with e.g. nginx and another container running pm2. Does PHP-PM not fully reserver port 81 inside the network defined by my docker-compose.yaml
file?
You must set --host=0.0.0.0
on your ENTRYPOINT
, otherwise process in container will listen on 127.0.0.1:81
(ie. localhost:81
) by default and will only be reachable from within this same container.
ENTRYPOINT ["/ppm/vendor/bin/ppm", \
"start", \
"--static-directory=public/", \
"--app-env=dev", \
"--host=0.0.0.0", \
"--port=81", \
"--socket-path=/ppm/run", \
"--pidfile=/ppm/ppm.pid", \
"--debug=1"]
When you curl
from within php_pm
container it works because you're reaching the server from localhost
, but curl
from another container won't work as you're trying to reach the server from a different host. Using 0.0.0.0:81
will allow you to reach server from another container.