-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
102 lines (79 loc) · 3.43 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
FROM php:8.2.22-fpm-alpine
LABEL maintainer="KumaCMS DOCKER MAINTAINER <pony@ponycool.com>"
ENV TIMEZONE=Asia/Shanghai
ENV VHOST_PATH=/etc/nginx/vhost
ENV PHP_FPM_CONF_PATH=/usr/local/etc/php-fpm.d
ENV APP_PATH=/opt/kumacms
#换为国内清华镜像,以加速docker image的制作速度,非中国境内用户请注释掉下面一条
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \
&& apk update && apk upgrade
# 设置时区
RUN apk add tzdata \
&& ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
&& echo ${TIMEZONE} > /etc/timezone
# 安装Nginx
RUN apk --no-cache add nginx
# 安装Supervisord,管理Nginx和PHP-FPM进程
RUN apk --no-cache add supervisor
# 创建www用户
RUN addgroup -g 1000 -S www && adduser -s /sbin/nologin -S -D -u 1000 -G www www
RUN set-eux; \
[ ! -d "$APP_PATH" ]; \
mkdir -p "$APP_PATH"; \
chown -R www:www "$APP_PATH"; \
chown -R www:www "/var/lib/nginx"
# PHPIZE_DEPS 包含 gcc g++ 等编译辅助类库,完成编译后删除
ENV apk add --no-cache $PHPIZE_DEPS && \
apk del $PHPIZE_DEPS
RUN apk add --no-cache freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev icu-dev && \
docker-php-ext-install bcmath && \
docker-php-ext-configure gd --with-freetype --with-jpeg && \
docker-php-ext-configure intl && \
docker-php-ext-install -j$(nproc) gd && \
docker-php-ext-install intl
# 配置PHP、FPM \
RUN sed -i 's/listen = 9000/listen = \/run\/php-fpm.sock/g' "$PHP_FPM_CONF_PATH/zz-docker.conf"
COPY deploy/conf/fpm-pool.conf "$PHP_FPM_CONF_PATH/www.conf"
COPY deploy/conf/php.ini "$PHP_INI_DIR/php.ini"
# 配置NGINX
COPY deploy/conf/nginx.conf /etc/nginx/nginx.conf
COPY deploy/conf/nginx.vh.default.conf "$VHOST_PATH/default.conf"
COPY deploy/conf/nginx.vh.kumacms.conf "$VHOST_PATH/kumacms.conf"
# 配置 supervisord
COPY deploy/conf/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# 配置默认测试文件
RUN set -eux; \
cd /var/www/html; \
{ \
echo '<div>Hello KumaCMS</div>'; \
} | tee index.html; \
{ \
echo '<?php'; \
echo ' phpinfo();'; \
} | tee index.php;
# 复制应用
COPY app "$APP_PATH/app"
COPY public "$APP_PATH/public"
COPY writable "$APP_PATH/writable"
COPY vendor "$APP_PATH/vendor"
COPY spark "$APP_PATH/spark"
COPY .env.dev "$APP_PATH/.env"
# 文件夹授权
RUN chown -R www.www /var/www/html && \
chown -R www.www "$APP_PATH" && \
chmod -R 777 "$APP_PATH/public/css" && \
chmod -R 777 "$APP_PATH/public/js" && \
chmod -R 777 "$APP_PATH/writable" && \
# 删除文件使用通配符不能使用双引号,通配符在引号内不会被扩展
rm -rf $APP_PATH/writable/cache/template/* && \
rm -rf $APP_PATH/writable/debugbar/*.json && \
rm -rf $APP_PATH/writable/logs/*.log && \
echo "jwt.secret=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)" >> "$APP_PATH/.env"
# 修改配置文件
# RUN sed -i 's/public array \$proxyIPs = \[\];/public array \$proxyIPs = \["172\.0\.0\.1\/8"=>"X-Forwarded-For","127\.0\.0\.1"=>"X-Forwarded-For","192\.168\.0\.0\/16"=>"X-Forwarded-For"\];/g' "$APP_PATH/app/Config/App.php"
VOLUME "$APP_PATH/writable"
WORKDIR "$APP_PATH"
EXPOSE 80
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
# 配置健康检查以验证一切是否已启动并正在运行
HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1/fpm-ping