DockerFile构建Nginx+PHP环境

先执行步骤23再执行第4docker build

1 Dockerfile 配置

扩展根据自己需要安装

FROM php:8.1-fpm-alpine

LABEL MAINTAINER="dorian.cn<XXXX@example.com>"

ENV TZ="Asia/Shanghai"

# 设置时区、创建www用户、安装依赖
RUN echo ${TZ} > /etc/timezone \
     && addgroup -g 1000 -S www && adduser -s /sbin/nologin -S -D -u 1000 -G www www \
     && apk add libstdc++ libzip-dev tzdata 

#安装Redis扩展
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
     && apk add --no-cache zlib-dev \
     && docker-php-source extract \
     && curl -L --insecure -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/5.3.4.tar.gz \
     && tar xfz /tmp/redis.tar.gz \
     && rm -r /tmp/redis.tar.gz \
     && mv phpredis-5.3.4 /usr/src/php/ext/redis \
     && docker-php-ext-install redis \
     && docker-php-source delete \
     && apk del .build-deps

#安装Zip扩展
RUN apk add --no-cache --virtual .build-deps zlib-dev libzip-dev \
    && docker-php-ext-install zip \
    && apk del .build-deps

#安装GD扩展
RUN apk add --no-cache freetype-dev libjpeg-turbo-dev libpng-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install gd

# docker-php-ext-install安装扩展。
RUN apk update \
    && apk add --no-cache nginx freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev  \
    && docker-php-ext-install -j$(nproc) pdo_mysql opcache bcmath mysqli 

# 安装swoole扩展
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
     && apk add --no-cache openssl-dev \
     && docker-php-source extract \
     && curl -L -o /tmp/swoole.tar.gz https://pecl.php.net/get/swoole-5.1.3.tgz \
     && tar xfz /tmp/swoole.tar.gz \
     && rm -r /tmp/swoole.tar.gz \
     && mv swoole-5.1.3 /usr/src/php/ext/swoole \
     && docker-php-ext-install swoole \
     && docker-php-source delete \
     && apk del .build-deps

WORKDIR /app
EXPOSE 80 8080

# Nginx配置
COPY default.conf /etc/nginx/http.d/
# 在run.sh
COPY run.sh /run.sh
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" && mkdir -p /run/nginx/ && chmod +x /run.sh
# 执行run.sh
ENTRYPOINT ["/run.sh"]

2 Nginx 配置

Vue+ThinkPHP前后分离项目为例

server {
     listen 80;
     listen  [::]:80;
     server_name localhost;

     location / {
          root /app/frontend;
          index index.html index.htm;
          try_files $uri $uri/ /index.html;
     }
}

server{
     listen 8080;
     listen  [::]:8080;
     server_name localhost;

     location / {
          root /app/backend/public;
          index index.html index.htm;
          if (!-f $request_filename) {
               rewrite ^(.*)$ /index.php?s=/$1 last;
          }
     }
     location ~ \.php$ {
          root /app/backend/public;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME /app/backend/public/$fastcgi_script_name;
          include fastcgi_params;
     }

}

再使用外部的nginxURL反向代理到不同的端口

3 启动命令

crond &
php-fpm &
nginx -g 'daemon off;

4 构建镜像

docker build -t nginx_php .

如果文件名称不是Dockerfile,加上-f [文件名] 参数

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇