docker 创建 php:8.3.2-fpm-alpine
docker 创建 php:8.3.2-fpm-alpine , 优点是images比较小,启动快
docker build -t php:8.3.2-fpm-alpine .
OR 指定文件:
docker build -f Dockerfile83 -t php:8.3.2-fpm-alpine .
Dockerfile:
FROM php:8.3.2-fpm-alpine LABEL MAINTAINER="xxx@qq.com" ENV TZ "Asia/Shanghai" ENV TERM xterm # 默认关闭opcode ENV OPCODE 0 # COPY ./conf.d/ $PHP_INI_DIR/conf.d/ # COPY composer.phar /usr/local/bin/composer # COPY www.conf /usr/local/etc/php-fpm.d/www.conf # 创建www用户 RUN addgroup -g 1000 -S www && adduser -s /sbin/nologin -S -D -u 1000 -G www www # 配置阿里云镜像源 RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories # PHPIZE_DEPS 包含 gcc g++ 等编译辅助类库,完成编译后删除 RUN apk add --no-cache $PHPIZE_DEPS \ && apk add --no-cache libstdc++ libzip-dev tzdata\ && apk update \ && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" \ && pecl install redis-6.0.2 \ && docker-php-ext-enable redis \ && apk del $PHPIZE_DEPS # docker-php-ext-install 指令已经包含编译辅助类库的删除逻辑 RUN apk add --no-cache freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev \ && apk update \ && docker-php-ext-configure gd --with-jpeg=/usr/include --with-freetype=/usr/include/freetype2/ \ && docker-php-ext-install -j$(nproc) gd \ && docker-php-ext-install -j$(nproc) pdo_mysql \ && docker-php-ext-install -j$(nproc) opcache \ && docker-php-ext-install -j$(nproc) bcmath \ && docker-php-ext-install -j$(nproc) mysqli \ && apk del freetype-dev libpng-dev libjpeg-turbo-dev \ && rm /var/cache/apk/* # RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" EXPOSE 9000 ENTRYPOINT ["php-fpm"]
相对之前的版本还是压缩不少空间的:
参考1: https://www.cnblogs.com/syushin/p/14955582.html
参考2: https://lihuaio.com/tech/docker/php-image/