在php容器中使用nginx

我有这个基于php-fpm的Dockerfile

FROM php:7.1-fpm RUN apt-get -y update && apt-get -y upgrade # Basics RUN apt-get -y install vim nano git curl cron zsh # www-data user RUN usermod -u 1000 www-data RUN apt-get update \ && apt-get install -y nginx \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ && echo "daemon off;" >> /etc/nginx/nginx.conf ADD default.conf /etc/nginx/sites-available/default ADD . /var/www WORKDIR /var/www EXPOSE 80 9000 CMD ["nginx"] 

我在这个镜像中安装了nginx,并添加了configuration: default.conf

 server { listen 80 default_server; listen [::]:80 default_server; root /var/www; index index.html index.htm index.php; server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } } 

这可以加载一个很好的HTML文件,但我不知道如何加载一个PHP文件,当我使用基于PHP的图像。

我没有find在这个php-fpm图像中使用快速CGI模式的PHP套接字。

使用单独的php-fpm容器,我将以这种方式进行pipe理:

 location ~ ^/(index)\.php(/|$) { fastcgi_pass php-fpm:9000; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; } 

但是我想用一个容器。 我该怎么做? 我怎样才能改变这一行?

fastcgi_pass php-fpm:9000;

有几种方法,

  1. phpnginx命令放在一个脚本中,比如run.sh ,然后是CMD run.sh
  2. 使用像supervisord这样的进程pipe理器

您可以使用现有的PHP-FPM + NGINX容器 。 或者你可以看看Container的dockerfile它可以提供一些帮助。