Lumen PHP 项目Dockerfile

这个文件是基于上两篇文章的项目内容,最终的Dockerfile基本如此:

FROM harbor.example.net/k8s-php/api:1.0.1

USER root

# 如需自定义优先级最高且不可覆盖的配置文件,参考https://dockerfile.readthedocs.io/en/latest/content/DockerImages/dockerfiles/php-nginx.html
# /opt/docker/etc/php/php.webdevops.ini 会覆盖为 /usr/local/etc/php/conf.d/98-webdevops.ini
# copy 99-docker.ini /opt/docker/etc/php/php.ini 此时的配置会覆盖为 /usr/local/etc/php/conf.d/99-docker.ini

# 进程数量配置,以1C2G计算,动态模式:启动 24,最小16,最大64,测试环境1/4, 同时,在测试环境开启错误输出
ENV ROCKETOS_ENVIRONMENT=pro \
    TZ=Asia/Shanghai \
    PHP_DISMOD=ioncube,memcached,mongodb,vips,amqp,gearman,memcache,opencc,pgsql,pdo_pgsql,soap,sysvmsg,sysvsem,sysvshm,imagick,gd,ldap,imap \
    FPM_PM_MAX_CHILDREN=32 \
    FPM_PM_START_SERVERS=12 \
    FPM_PM_MIN_SPARE_SERVERS=8 \
    FPM_PM_MAX_SPARE_SERVERS=32

ARG CI_COMMIT_REF_NAME
ENV APP_HOME=/data/htdocs/k8s-php-api/

ARG CI_COMMIT_SHA
ARG CI_BUILD_DATETIME
ENV ROCKETOS_BUILD_VERSION="${CI_COMMIT_SHA}_${CI_COMMIT_REF_NAME}_${CI_BUILD_DATETIME}"

COPY . $APP_HOME

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
    && mkdir -p /data/core_config/ \
    && mkdir -p /data/logs/ \
    && mkdir -p /data/app_config/ \
    && echo "1" > /data/app_config/need-php-fpm.txt \
    && echo "1" > /data/app_config/need-app-customer.txt \
    && cd ${APP_HOME} \
    && rm -rf ${APP_HOME}.gitlab-ci.yml \
    && cp ${APP_HOME}.env.production ${APP_HOME}.env \
    && rm -rf ${APP_HOME}.env.* \
    && mv ${APP_HOME}.env ${APP_HOME}.env.production \
    && sed -i 's/\r/\n/g; s/\n$//' ${APP_HOME}docker/*/* \
    && sed -i 's/\r/\n/g; s/\n$//' ${APP_HOME}cli/apollo/*.sh \
    && cp -rf ${APP_HOME}docker/config/nginx.vhost.conf /opt/docker/etc/nginx/vhost.conf \
    && cp -rf ${APP_HOME}docker/config/nginx.http.conf /etc/nginx/nginx.conf \
    && cp -rf ${APP_HOME}docker/config/nginx.10-log.conf /opt/docker/etc/nginx/vhost.common.d/10-log.conf \
    && cp -rf ${APP_HOME}docker/supervisor.d/*.conf /opt/docker/etc/supervisor.d/ \
    && rm -f /opt/docker/etc/supervisor.d/*.dev.conf \
    && mv /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini \
    && cat ${APP_HOME}docker/config/php.ini >> /opt/docker/etc/php/php.webdevops.ini \
    && cat ${APP_HOME}docker/config/php-fpm.global.conf >> /opt/docker/etc/php/fpm/php-fpm.conf \
    && cat ${APP_HOME}docker/config/php-fpm.application.pro.conf >> /opt/docker/etc/php/fpm/pool.d/application.conf \
    && cp -rf ${APP_HOME}docker/config/crontab.cron /opt/docker/etc/cron/crontab \
    && touch /data/logs/crontab.log \
    && touch /data/logs/crontab.error.log \
    && docker-service-enable cron \
    && composer dump-autoload --no-interaction --classmap-authoritative --no-dev -vv --no-ansi \
    && chown -Rf application:application /data/core_config/ \
    && chmod 777 /data/logs/ \
    && chmod 777 /data/logs/* \
    && chown -Rf application:application /data/htdocs/k8s-php-api/storage

ENTRYPOINT ["/entrypoint"]
CMD ["supervisord"]

EXPOSE 8080 80

这个Dockerfile的目的是为了生成最终执行的Dockerfile, 其中包含了nginx, php-fpm, log, crontab 等基本组件,同时提供一些php-fpm的配置选项

当前还没有任何评论

写下你最简单的想法