Nginx+PHP7+FFMpeg的集成Docker镜像制作

Dockerfile及其说明

RUN apt-get update \
&& export LANG=C.UTF-8 \
&& apt-get install software-properties-common -y \
&& apt-get install python-software-properties -y \
&& add-apt-repository ppa:ondrej/php -y \
&& add-apt-repository ppa:nginx/stable -y \
&& apt-get install -y php7.0 php7.0-mysql php7.0-curl php7.0-json php7.0-cgi php7.0-fpm \
&& apt-get install nginx -y \
&& apt-get install ffmpeg -y \
&& apt-get install supervisor -y \
&& mkdir /run/php \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& echo "daemon off;" >> /etc/nginx/nginx.conf

# COPY default /etc/nginx/sites-enabled/
# COPY supervisord.conf /etc/supervisord.conf
COPY supervisord.conf /etc/
COPY nginx-php.conf /etc/supervisor/conf.d/

VOLUME ['/etc/nginx/sites-enabled','/var/www']
ENTRYPOINT ["/usr/bin/supervisord","-c","/etc/supervisord.conf"]
EXPOSE 80

来源镜像使用了Ubuntu,使用了supervisor来管理容器内进程。

构建方式:

docker run --name nginx-php -p 8001:80 -v /project/nginx_conf/:/etc/nginx/sites-enabled -v /project/www/:/var/www/ -d a:1

Dokcerfile上下文介绍

Nginx+PHP7+FFMpeg的集成Docker镜像制作_第1张图片
image.png

supervisor配置文件,supervisor.conf

[unix_http_server]
file=/var/run/supervisor.sock

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisord]
nodaemon=true

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock

[include]
files = /etc/supervisor/conf.d/*.conf

supervisor配置管理nginx+php文件,nginx-php.conf

[program:nginx]
command=nginx
[program:php-fpm7.0]
command=php-fpm7.0

sources.list是Ubuntu的源:

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

Nginx的目录

因为nginx配置文件夹/etc/nginx/sites-enabled被我挂载出来了,nginx.conf这个文件里面写了会加载/etc/nginx/sites-enabled这个文件夹的所有内容。

放在nginx_conf文件夹下的default文件夹如下:

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 80 default_server;
    # listen [::]:80 default_server; 
    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.php index.nginx-debian.html;

    server_name aaa.com;

    location / {
        try_files $uri $uri/ =404;
    }
    set        $root    /var/www/html;
    location ~ .+\.php($|/) {
    set $script $uri;
    set $path_info "";
    if ($uri ~ "^(.+\.php)(/.+)") {
        set $script $1;
        set $path_info $2;
    }
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_index    index.php?IF_REWRITE=1;
    fastcgi_param    PATH_INFO    $path_info;
    fastcgi_param    SCRIPT_FILENAME    $root$fastcgi_script_name;
    fastcgi_param    SCRIPT_NAME    $script;
    include        fastcgi_params;
    }

}

注意:ipv6的端口映射要注释了,Ubuntu Docker镜像还不支持ipv6的包。

你可能感兴趣的:(Nginx+PHP7+FFMpeg的集成Docker镜像制作)