I’m using php-fpm
which runs for default on the port 9000
. The problem’s that I have other docker container based on php-fpm
, so I need to change the default port to another one, in order to not confuse nginx
.
This is my Dockerfile
:
FROM php:8.0.2-fpm-alpine
RUN sed -i 's/9000/9001/' /usr/local/etc/php-fpm.d/zz-docker.conf
WORKDIR /var/www/html
CMD ["php-fpm"]
EXPOSE 9001
I tried to use the sed
command to replace the port 9000
with 9001
.
Inside my docker-compose
file I have this configuration:
version: '3.9'
services:
php-fpm:
container_name: app
restart: always
build:
context: .
dockerfile: ./docker/php-fpm/Dockerfile
ports:
- "9001:9000"
volumes:
- ./src:/var/www/html
- ./docker/php-fpm/config/www.conf:/usr/local/etc/php-fpm.d/www.conf
- ./src/public:/app/public
- ./src/writable:/app/writable
nginx:
image: nginx:stable-alpine
container_name: nginx
restart: always
volumes:
- ./src:/var/www/html
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/sites/:/etc/nginx/sites-available
- ./docker/nginx/conf.d/:/etc/nginx/conf.d
depends_on:
- php-fpm
environment:
VIRTUAL_HOST: ${HOST}
LETSENCRYPT_HOST: ${HOST}
LETSENCRYPT_EMAIL: ${EMAIL}
as you can see I have exposed the port 9001
also in the docker-compose
file.
The file default.conf
available within conf.d
folder contains this:
upstream php-upstream {
server php-fpm:9001;
}
the problem’s that for some reason, when I load my site I get the error 500. So this means that the stream doesn’t send any signal. If I change to port 9000
everything works, but the stream is wrong ’cause it’s the content of another application.
How can I correctly change the default port?
3
Answers
Keep in mind that your nginx docker connects via the internal docker net work, your docker host port mapping
9001:9000
is not taken into account.If your php-fpm is really listening on port 9001, then that is the port you must use in your nginx config.
Also
EXPOSE
is primarily declarative and does not expose anything by itself (https://docs.docker.com/engine/reference/builder/#expose) the corresponding service must still be configured correctly to use that port.I think the problem is not the sed command itself, it’s related to the wrong file you mentioned for it.
this is the file you are trying to change the port in it but inside your docker-compose file you are mapping something else
for this line in Dockerfile is not working(?):
RUN sed -i 's/9000/9001/' /usr/local/etc/php-fpm.d/zz-docker.conf
so I decided to make this change after the container is up with:
docker exec -i your_container bash -c 'sed -i 's/9000/9001/' /usr/local/etc/php-fpm.d/zz-docker.conf'
and then restert the container to make changes happened
hope help you