概述

阿里云的国内源加速

安装了一些工具

  • cron、curl、telnet、git、zlib1g-dev、nginx、supervisor、libzip-dev、unzip、procps、sudo、vim

    安装了一些常用的PHP扩展

  • composer、gd、xdebug、zip、pdo_mysql、opcache、mysqli、bcmath、redis、mongodb、swoole

    安装了supervisor守护进程,保证进程安全运行

    ├── code
    │   └── index.php
    ├── conf
    │   └── nginx.conf
    ├── install
    │   ├── init.sh
    │   └── install-php-extensions
    ├── logs
    │   ├── nginx
    │   │   ├── access.log
    │   │   ├── error.log
    │   │   ├── www.test.com_access.log
    │   │   └── www.test.com_error.log
    │   └── php
    │       └── php_errors.log
    ├── REAMME.md
    └── web.Dockerfile

web.Dockerfile

FROM php:7.4-fpm

MAINTAINER ZhengNiu "771036148@qq.com"

COPY ./install/install-php-extensions /usr/local/bin/

RUN sed -i "s#http://deb.debian.org#http://mirrors.aliyun.com#g" /etc/apt/sources.list && \
    rm -rf /var/lib/apt/lists/* && \
    chmod +x /usr/local/bin/install-php-extensions && \
    apt-get update && \
    apt-get install -y cron curl telnet git zlib1g-dev nginx supervisor  libzip-dev unzip procps sudo vim && \
    /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone && \
#    php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" && \
#    php composer-setup.php --install-dir=/usr/local/bin --filename=composer && \
#    php -r "unlink('composer-setup.php');" && \
    apt-get clean && rm -rf /var/cache/apt/* && \
    install-php-extensions gd xdebug zip pdo_mysql opcache mysqli bcmath redis mongodb swoole @composer && \
    unlink /etc/nginx/sites-enabled/default && \
    /bin/cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini && \
    sed -i "482c display_errors = On" /usr/local/etc/php/php.ini && \
    sed -i "503c log_errors = On" /usr/local/etc/php/php.ini && \
    sed -i "586c error_log = /var/log/php/php_errors.log" /usr/local/etc/php/php.ini && \
    sed -i "12c nodaemon=true" /etc/supervisor/supervisord.conf && \
    echo "[program:cron]\ncommand=cron -f\n\n[program:nginx]\ncommand=/usr/sbin/nginx -g 'daemon off;'\n\n[program:php]\ncommand=/usr/local/sbin/php-fpm --nodaemonize" > /etc/supervisor/conf.d/web.conf

WORKDIR /var/www/html

EXPOSE 80

CMD ["supervisord","-c","/etc/supervisor/supervisord.conf"]

准备nginx.conf 配置文件

server {
     listen       80;
     server_name  www.test.com;
     root   /var/www/html;
     index index.html index.htm index.php;

     access_log /var/log/nginx/www.test.com_access.log;
     error_log /var/log/nginx/www.test.com_error.log;

     location / {
         try_files $uri $uri/ /index.php?$query_string;
     }

     error_page 404 /index.php;

     location ~ \.php$ {
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include        fastcgi_params;
     }

     location ~ /\.(?!well-known).* {
         deny all;
     }
}

准备index.php入口文件

<?php

phpinfo();

构建镜像 && 启动容器

//构建镜像
docker build -t web:1.0 -f web.Dockerfile .

//运行容器
docker run --name web -d -p 80:80 -v $PWD/code:/var/www/html -v $PWD/conf:/etc/nginx/conf.d -v $PWD/logs:/var/log web:1.0
Last modification:June 14, 2022
如果觉得我的文章对你有用,请随意赞赏