从零搭建hyperf docker镜像

  • Post author:
  • Post category:其他



hyperf官方镜像中无法通过pecl安装扩展,使用起来很不方便,只好自己搭建一个了。

FROM php:7.4-cli
# 设置时区
ENV TZ=Asia/Shanghai
# 安装 PECL 拓展,安装Redis, swoole

RUN apt-get update && apt-get install -y --no-install-recommends \
	#图像处理、验证码可能需要
	libfreetype6-dev libjpeg62-turbo-dev libpng-dev libzip-dev\
    && pecl install redis-5.3.4 \
    && pecl install swoole-4.8.8 \
#    && pecl install protobuf \
    && docker-php-ext-enable redis swoole \
    && docker-php-ext-configure gd --with-jpeg=/usr/include --with-freetype=/usr/include/freetype2/ \
    && docker-php-ext-install -j$(nproc) pcntl gd zip  pdo_mysql opcache \
    && mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" \
    && echo "swoole.use_shortname='Off'" >>  /usr/local/etc/php/conf.d/default.ini \
    && echo "memory_limit=1G" >>  /usr/local/etc/php/conf.d/default.ini \
    && echo "opache.enable_cli='on'" >>  /usr/local/etc/php/conf.d/default.ini \
    && php -m

# 安装 Composer
ENV COMPOSER_HOME /root/composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
ENV PATH $COMPOSER_HOME/vendor/bin:$PATH

#指定镜像工作目录
WORKDIR /opt/www


#将代码放在code中
COPY code /opt/www
RUN composer install --no-dev -o && php bin/hyperf.php

EXPOSE 9501
CMD ["php", "/opt/www/bin/hyperf.php", "start"]
#ENTRYPOINT ["php", "/opt/www/bin/hyperf.php", "start"]



版权声明:本文为kkyy3210原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。