文档说明:只记录关键地方;
构建脚本 php-cli-alpine
#!/bin/sh
set -ux
TIME=`date -u '+%Y%m%dT%H%M%SZ'`
VERSION="7.4-cli-alpine-"${TIME}
IMAGE="wenba100xie/php:${VERSION}"
export DOCKER_BUILDKIT=1
# 使用代理 需要传递两个参数
# sh build-docker.sh --proxy 1
PROXY_URL=${2:+'http://192.168.3.26:8015'}
docker build -t ${IMAGE} -f Dockerfile . --progress=plain --build-arg PROXY_URL=$PROXY_URL
docker push ${IMAGE}
构建之前查看基础镜像默认配置
docker run --rm php:7.4-cli-alpine php -i | grep php.ini
docker run --rm php:7.4-cli-alpine php -m
构建php cli
FROM php:7.4-cli-alpine
RUN sed -i "[email protected]/@mirrors.tuna.tsinghua.edu.cn/@g" /etc/apk/repositories
RUN uname -a
RUN apk update && apk add --no-cache ca-certificates openssl openssl-dev
RUN apk add --no-cache \
freetype \
freetype-dev \
jpeg \
libpng \
libwebp \
libpng \
libpng-dev \
libjpeg-turbo \
libjpeg-turbo-dev \
gd-dev \
zlib-dev \
gmp \
gmp-dev \
glib \
glib-dev \
libzip-dev \
postgresql-dev \
tini
RUN apk add build-base autoconf curl
#RUN addgroup -g 1000 -S nginx && adduser -u 1000 -S nginx -G nginx -s /sbin/nologin
ARG PROXY_URL=''
ENV http_proxy=$PROXY_URL
ENV https_proxy=$PROXY_URL
RUN apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
RUN pear config-set http_proxy $PROXY_URL
RUN pecl channel-update https://pecl.php.net/channel.xml
RUN pear update-channels
WORKDIR /
RUN pecl install redis
RUN pecl install mongodb
RUN pecl install swoole
# curl ssl 证书
# https://curl.haxx.se/docs/caextract.html curl ssl 证书下载网址
RUN curl -fsSL 'https://curl.haxx.se/ca/cacert.pem' -o /usr/local/etc/php/cacert.pem
ENV http_proxy=""
ENV https_proxy=$http_proxy
RUN pear config-set http_proxy ""
# 启用扩展
RUN docker-php-ext-enable redis
RUN docker-php-ext-enable mongodb
RUN docker-php-ext-enable swoole
# php 源码所在目录 /usr/src/php
RUN docker-php-source extract
RUN docker-php-ext-install gd pdo_mysql pdo_pgsql sockets bcmath gmp zip
# /usr/local/etc/php/php.ini
RUN docker-php-source delete
ENV TZ=Etc/UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN curl -fsSL 'https://curl.haxx.se/ca/cacert.pem' -o /etc/php/cacert.pem
RUN curl -Lo /usr/local/bin/composer https://mirrors.aliyun.com/composer/composer.phar
RUN chmod a+x /usr/local/bin/composer
RUN rm -rf /var/cache/apk/* /tmp
WORKDIR /
# USER 1000:1000
构建脚本 php-fpm-alpine
#!/bin/sh
set -ux
TIME=`date -u '+%Y%m%dT%H%M%SZ'`
VERSION="7.4-fpm-alpine-"${TIME}
IMAGE="wenba100xie/php:${VERSION}"
export DOCKER_BUILDKIT=1
# 使用代理 需要传递两个参数
# sh build-docker.sh --proxy 1
PROXY_URL=${2:+'http://192.168.3.26:8015'}
docker build -t ${IMAGE} -f Dockerfile . --progress=plain --build-arg PROXY_URL=$PROXY_URL
docker push ${IMAGE}
构建之前查看基础镜像默认配置
docker run --rm --name php-fpm php:7.4-fpm-alpine
docker exec -i php-fpm php -i | grep php.ini
docker exec -i php-fpm php -m
构建php php-fpm
FROM php:7.4-fpm-alpine
RUN sed -i "[email protected]/@mirrors.tuna.tsinghua.edu.cn/@g" /etc/apk/repositories
RUN uname -a
RUN apk update && apk add --no-cache ca-certificates openssl openssl-dev
RUN apk add --no-cache \
freetype \
freetype-dev \
jpeg \
libpng \
libwebp \
libpng \
libpng-dev \
libjpeg-turbo \
libjpeg-turbo-dev \
gd-dev \
zlib-dev \
gmp \
gmp-dev \
glib \
glib-dev \
libzip-dev \
postgresql-dev \
tini
RUN apk add build-base autoconf curl
#RUN addgroup -g 1000 -S nginx && adduser -u 1000 -S nginx -G nginx -s /sbin/nologin
ARG PROXY_URL=''
ENV http_proxy=$PROXY_URL
ENV https_proxy=$PROXY_URL
RUN apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
RUN pear config-set http_proxy $PROXY_URL
RUN pecl channel-update https://pecl.php.net/channel.xml
RUN pear update-channels
WORKDIR /
RUN pecl install redis
RUN pecl install mongodb
# curl ssl 证书
# https://curl.haxx.se/docs/caextract.html curl ssl 证书下载网址
RUN curl -fsSL 'https://curl.haxx.se/ca/cacert.pem' -o /usr/local/etc/php/cacert.pem
ENV http_proxy=""
ENV https_proxy=$http_proxy
RUN pear config-set http_proxy ""
# 启用扩展
RUN docker-php-ext-enable redis
RUN docker-php-ext-enable mongodb
# php 源码所在目录 /usr/src/php
RUN docker-php-source extract
RUN docker-php-ext-install gd pdo_mysql pdo_pgsql sockets bcmath gmp zip
# /usr/local/etc/php/php.ini
RUN docker-php-source delete
ENV TZ=Etc/UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN curl -fsSL 'https://curl.haxx.se/ca/cacert.pem' -o /etc/php/cacert.pem
RUN curl -Lo /usr/local/bin/composer https://mirrors.aliyun.com/composer/composer.phar
RUN chmod a+x /usr/local/bin/composer
RUN rm -rf /var/cache/apk/* /tmp
WORKDIR /
# USER 1000:1000
参考文档
- hub docker php
- github docker php
- hub docker php
- hub docker nginx
- curl ssl 证书
- PHP四种设置回调函数的方式
- Unix 系统下的安装
- php docs
- php 所支持的时区列表
- 阿里云 Composer 全量镜像
- 最新的 Composer 版本
- PHP packagist.org
- PHP 搜扩展包
- symfony
- laravel/laravel
- Dockerfile
- Compose file
- Tini作为Docker容器的init进程,tini 解决僵尸进程