Docker 有一个开放的端口,但配置文件中没有描述?
Docker has an opened port, but it's not described in configuration files?
我有 2 个 Dockerfile:一个带有 nginx,另一个带有 php。 php 的容器暴露了 9000 端口,但在 docker-compose.yml 或 Dockerfile.
中没有描述。
是什么让docker打开9000端口?
有人遇到过这个问题吗?任何帮助将不胜感激 )))
重现步骤
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"]
nginx 配置文件的一部分
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
这是因为它暴露在父docker图像中(php:7.4-fpm)
https://github.com/docker-library/php/blob/master/7.3/alpine3.12/fpm/Dockerfile#L233
您的 PHP Dockerfile 声明 FROM php:7.4-fpm
php:7.4-fpm
暴露了端口 9000。
我有 2 个 Dockerfile:一个带有 nginx,另一个带有 php。 php 的容器暴露了 9000 端口,但在 docker-compose.yml 或 Dockerfile.
中没有描述。是什么让docker打开9000端口?
有人遇到过这个问题吗?任何帮助将不胜感激 )))
重现步骤
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"]
nginx 配置文件的一部分
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
这是因为它暴露在父docker图像中(php:7.4-fpm)
https://github.com/docker-library/php/blob/master/7.3/alpine3.12/fpm/Dockerfile#L233
您的 PHP Dockerfile 声明 FROM php:7.4-fpm
php:7.4-fpm
暴露了端口 9000。