skip to Main Content

I have 2 Dockerfiles: one with nginx and another with php. Container with php exposes port 9000, but it is not described in docker-compose.yml or Dockerfile.

What makes docker to open the port 9000?

Does anyone come across this problem? Any help is be appreciated )))

Steps to reproduce

docker-compose.yml

version: "3.4"

services:
    nginx:
        build:
            context: .
            dockerfile: ./Dockerfile-Nginx
        container_name: nginx
        image: nginx
        ports:
            - "80:80"
            - "443:443"
        volumes:
            - ./web:/var/www/vhosts
            - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
            - ./config/nginx/common-nginx-host.conf:/etc/nginx/common-nginx-host.conf:ro
            - ./config/nginx/csp.conf:/etc/nginx/csp.conf:ro
            - ./config/nginx/expires-map.conf:/etc/nginx/expires-map.conf:ro
            - ./config/nginx/mime.types:/etc/nginx/mime.types:ro
            - ./config/nginx/sites-enabled:/etc/nginx/sites-enabled:ro
            - ./logs/nginx:/var/log/nginx
            - ./data/letsencrypt:/etc/letsencrypt
        environment:
            - TZ=Etc/UTC
        links:
            - php
        networks:
          - local
        restart: always
    php:
        build:
            context: .
            dockerfile: ./Dockerfile-PHP7.4
        container_name: php
        image: php
        volumes:
            - ./web:/var/www/vhosts
            - ./logs/php/7.4:/var/log/php
            - ./config/php/7.4/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro
        environment:
            - TZ=Etc/UTC
        networks:
            - local
        restart: always
    networks:
        local:
           driver: bridge

Dockerfile-Nginx

FROM ubuntu:latest as nginx

RUN 
        apt-get -yqq update && 
        apt-get -yqq install nginx && 
        apt-get install -y tzdata && 
        apt-get install -yqq --no-install-recommends apt-utils && 
        apt-get -yqq install software-properties-common && 
        apt-get -yqq install && 
        LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php && apt-get update && 
        apt-get install -yqq php7.4 php7.4-cli php7.4-common php7.4-mysql && 
        apt-get -yqq install letsencrypt && 
        apt-get clean


WORKDIR /var/www/vhosts

CMD ["nginx", "-g", "daemon off;"]

Dockerfile-PHP7.4

FROM php:7.4-fpm as php-fpm-7.4

RUN 
        apt-get update  -yqq && 
        apt-get install -yqq 
                xvfb libfontconfig wkhtmltopdf 
                git sass 
                libpng-dev 
                libjpeg-dev 
                libzip-dev 
                libfreetype6-dev 
        libxrender1 
        libfontconfig1 
        libx11-dev 
        libxtst6 
        zlib1g-dev 
        imagemagick 
        libmagickwand-dev 
        libmagickcore-dev 
        libmemcached-dev && 
        pecl install memcached && 
    yes '' | pecl install imagick && 
        docker-php-ext-install gd && 
    docker-php-ext-enable gd && 
    docker-php-ext-enable imagick && 
    docker-php-ext-enable memcached && 
        docker-php-ext-configure pdo_mysql --with-pdo-mysql && 
        docker-php-ext-install -j$(nproc) 
        pdo_mysql 
    zip

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY config/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml


RUN ${TZ} > /etc/timezone

CMD ["php-fpm"]

Part of nginx config file

location /index.php {

                # Rate limiting
                limit_req zone=defaultlimit burst=40 nodelay;
                limit_req_status 444;
                limit_req_log_level warn;

                fastcgi_split_path_info  ^(.+.php)(.*)$;

                set $fsn /index.php;
                if (-f $document_root$fastcgi_script_name){
                        set $fsn $fastcgi_script_name;
                }

                #include snippets/fastcgi-php.conf;
                fastcgi_pass php:9000;

                include fastcgi_params;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;

                #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
                fastcgi_param  PATH_INFO        $fastcgi_path_info;
                fastcgi_param  PATH_TRANSLATED  $document_root$fsn;
        }

Docker opend port 9000

2

Answers


  1. It s because it s exposed into the parent docker image (php:7.4-fpm)

    https://github.com/docker-library/php/blob/master/7.3/alpine3.12/fpm/Dockerfile#L233

    Login or Signup to reply.
  2. Your PHP Dockerfile states FROM php:7.4-fpm

    That php:7.4-fpm exposes the port 9000.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search