我想在群集中运行用php编写的服务。所以我在用docker。 这是堆栈:
在本地开发中,与服务和nginx共享卷没有问题,但是在生产中,这是一种不好的方法。 当我尝试使用php-fpm和nginx来构建映像时,php-fpm总是崩溃。这是错误:
service_1_5631b886cf08 | [10-Dec-2018 21:48:42] NOTICE: [pool www]
child 22 started
service_1_5631b886cf08 | [10-Dec-2018 21:48:42] WARNING: [pool www]
child 21 exited on signal 11 (SIGSEGV - core dumped) after 26.338965
seconds from start
service_1_5631b886cf08 | [10-Dec-2018 21:48:42] NOTICE: [pool www]
child 23 started
这是Dockerfile:
FROM php:7.2-fpm-stretch
ENV PHPREDIS_VERSION 4.1.1
ENV AMQP_VERSION 1.9.3
# Mcrypt
#RUN apt-get install -y libmcrypt-dev && docker-php-ext-install -j$(nproc) mcrypt
# GD
RUN apt-get update \
&& apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
RUN docker-php-ext-configure gd \
--with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
# PDO
RUN docker-php-ext-install -j$(nproc) pdo && \
&& docker-php-ext-install -j$(nproc) pdo_mysql
# Postgres PDO
RUN apt-get install -y libpq-dev \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo_pgsql
# Redis
RUN mkdir -p /usr/src/php/ext/redis \
&& curl -L https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz | tar xvz -C /usr/src/php/ext/redis --strip 1 \
&& echo 'redis' >> /usr/src/php-available-exts \
&& docker-php-ext-install redis
# INTL
RUN apt-get install -y zlib1g-dev libicu-dev g++ \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl
# OPCACHE
RUN docker-php-ext-install -j$(nproc) opcache
# APCu
RUN pecl install apcu && docker-php-ext-enable apcu
# zip
RUN docker-php-ext-install -j$(nproc) zip
# AMQP
RUN apt-get install -y librabbitmq-dev \
&& pecl install amqp-$AMQP_VERSION \
&& docker-php-ext-enable amqp
# Nginx
RUN apt-get update \
&& apt-get install -y nginx \
&& chown -R www-data:www-data /var/lib/nginx
# supervisor
RUN apt install -y supervisor \
&& mkdir -p /var/log/supervisor \
&& rm -rf /var/lib/apt/lists/*
# composer
RUN curl -sL https://getcomposer.org/installer | php -- --install-dir /usr/bin --filename composer
WORKDIR /var/www/service/service_1
ADD . /var/www/service/service_1
RUN mv nginx.conf.tmpl /etc/nginx/nginx.conf \
&& mv supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN composer install --no-plugins --no-scripts
# php-fpm
EXPOSE 9000
# nginx
EXPOSE 8180
CMD ["/usr/bin/supervisord"]
以下是用于服务的Nginx配置:
upstream service {
server localhost:9000;
}
server {
listen 8180;
server_name localhost;
root /var/www/services/service_1/public;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass service;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
# error_log /var/log/nginx/project_error.log;
# access_log /var/log/nginx/project_access.log;
}
和监督配置:
[supervisord]
nodaemon = true
logfile = /dev/null
logfile_maxbytes = 0
[program:php-fpm]
command = /usr/local/sbin/php-fpm
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0
[program:nginx]
command = /usr/sbin/nginx -g "daemon off;"
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0
我该怎么办?主要目的是,我不想在Nginx和php-fpm容器上都使用带有代码的卷,所以我试图使它们与之一起工作