Php: Custom/parametrized port for fpm

Created on 14 Aug 2017  路  4Comments  路  Source: docker-library/php

Would not it be convenient to handle the fpm port (9000) in a custom way? So on compose or on run you can start it with the port we prefer. You would avoid conflicts with xdebug and you could start multiple fpm services on the same web server...

Most helpful comment

@tianon

Thanks. I had the same problem and your sed snippet did the trick.
Just a small correction:

FROM php:7.2-fpm
RUN sed -i 's/9000/3001/' /usr/local/etc/php-fpm.d/zz-docker.conf

There are no colons in the zz-docker.conf :)

Cheers!

All 4 comments

Each FPM running in its own container will not have a port conflict with any other FPM running on the server. There are two ways to handle them.

Run a load balancer like Nginx to proxy to the correct FPM container; this would access each FPM via its container IP at port 9000. This works great since you have to run something that speaks the FPM protocol in order to serve any web requests. This can easily be spread over multiple machines with Docker Swarm mode. This would also prevent any of the FPM ports from being potentially publicly accessible.

Alternatively, with compose you can just map a different host port to the container port. Note that you would still need to run something like Nginx in order to route web requests to the FPM service.

# this would make this FPM service available at port 9001 on the Docker host
  ports:
    - "9001:9000"

# or let Docker choose a high unused port like 32768 to use on the host
  ports:
    - "9000"

Except if one wanted to use host networking, then there isn't any port mapping happening. I agree with @bsramin , it would be nice to be able to overwrite the 9000.

If adjusting the default port is required, then as noted in https://github.com/docker-library/php/issues/241, one should simply remove, replace, or adjust the configuration file in question. Something simple like the following should do the trick:

FROM php:7.2-fpm
RUN sed -i 's/:9000/:3001/' /usr/local/etc/php-fpm.d/zz-docker.conf

(which adjusts the port from 9000 to 3001 instead -- this could obviously be done via a custom docker run command as well, something like docker run php:7.2-fpm sh -c 'sed ... && exec php-fpm')

@tianon

Thanks. I had the same problem and your sed snippet did the trick.
Just a small correction:

FROM php:7.2-fpm
RUN sed -i 's/9000/3001/' /usr/local/etc/php-fpm.d/zz-docker.conf

There are no colons in the zz-docker.conf :)

Cheers!

Was this page helpful?
0 / 5 - 0 ratings