生成包含常用扩展的docker php-fpm镜像含 php5.6 php7.1 php7.2 php7.4的dokcerfile(亲测可用2022-11-28)

引言:使用docker容器可用很方便并快速的启动各种应用,不过PHP官方镜像只有最基本的php源码,像redis,mysql等很常见的扩展都没有包含,所以有必要制作包括常用扩容的php镜像,以下几个php版本是经本人验证可用使用的dockerfile,可用只有拿去使用

1、php:5.6-fpm 

FROM php:5.6-fpm

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
libmemcached-dev \
zlib1g-dev \
libbz2-dev \
libgmp-dev \
libedit-dev \
libxml2-dev \
libxslt-dev \
openssl \
libssl-dev \
libpq-dev \
&& docker-php-ext-install -j$(nproc) iconv \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd  \
bcmath \
mysqli \
pdo_mysql \
bz2 \
calendar \
exif \
gettext \
intl \
pcntl \
readline \
pgsql \
pdo_pgsql \
shmop \
sockets \
wddx \
xsl \
zip \
opcache \
mcrypt \
&& pecl install igbinary-1.2.1 && docker-php-ext-enable igbinary \
&& echo "\n" | pecl install redis && docker-php-ext-enable redis \
&& echo "\n" | pecl install memcache && docker-php-ext-enable memcache \
&& echo "\n" | pecl install memcached-2.2.0  && docker-php-ext-enable memcached \
&& pecl install mongodb && docker-php-ext-enable mongodb \
&& echo "\n" | pecl install mongo && docker-php-ext-enable mongo \
&& docker-php-source delete \
&& apt-get clean; rm -rf /var/lib/apt/lists/

 

2、php:7.1-fpm

FROM php:7.1-fpm

# 设置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 更新为国内镜像
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak \
&& echo 'deb http://mirrors.ustc.edu.cn/debian stable main contrib non-free' > /etc/apt/sources.list \
&& echo 'deb-src http://mirrors.ustc.edu.cn/debian stable main contrib non-free' >> /etc/apt/sources.list \
&& echo 'deb http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free' >> /etc/apt/sources.list \
&& echo 'deb-src http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free' >> /etc/apt/sources.list \
&& echo 'deb http://ftp.cn.debian.org/debian/ jessie main non-free' >> /etc/apt/sources.list

# 更新安装依赖包和PHP核心拓展
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libbz2-dev \
libcurl4-gnutls-dev \
&& docker-php-ext-install mysqli pdo pdo_mysql opcache json calendar bcmath zip bz2 mbstring curl \
&& rm -r /var/lib/apt/lists/*

# GD 扩展
RUN apt-get install -y --no-install-recommends libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
&& rm -r /var/lib/apt/lists/* \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd

# Redis、Xdebug扩展
RUN pecl install redis-5.1.1 \
&& pecl install xdebug-2.8.1 \
&& docker-php-ext-enable redis xdebug

# amqp 扩展
RUN apt-get update && apt-get install -y librabbitmq-dev libssl-dev \
&& pecl install amqp \
&& docker-php-ext-enable amqp


## imagick 扩展
#RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
# && apt-get install -y --no-install-recommends libmagickwand-dev \
# && rm -r /var/lib/apt/lists/* \
# && pecl install imagick-3.4.4 \
# && docker-php-ext-enable imagick

# mcrypt 扩展
RUN apt-get install -y --no-install-recommends libmcrypt-dev \
&& rm -r /var/lib/apt/lists/* \
&& pecl install mcrypt-1.0.0 \
&& docker-php-ext-enable mcrypt

# Memcached 扩展
#RUN apt-get install -y --no-install-recommends libmemcached-dev zlib1g-dev \
# && rm -r /var/lib/apt/lists/* \
# && pecl install memcached-3.1.3 \
# && docker-php-ext-enable memcached

# opcache 扩展
RUN docker-php-ext-configure opcache --enable-opcache && docker-php-ext-install opcache

# 安装第三方拓展,这里是 Phalcon 拓展
#RUN cd /home \
# && tar -zxvf cphalcon.tar.gz \
# && mv cphalcon-* phalcon \
# && cd phalcon/build \
# && ./install \
# && echo "extension=phalcon.so" > /usr/local/etc/php/conf.d/phalcon.ini

# 安装 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 /data
## Write Permission
#RUN usermod -u 1000 www-data

LABEL Author="walkingsun"
LABEL Version="2020.06"
LABEL Description="PHP 7.1 开发环境镜像. "

3、php:7.2-fpm

FROM daocloud.io/php:7.2-fpm-alpine

LABEL maintainer="lestat@lestat.me"

# 修改镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

# 安装依赖,核心扩展,pecl扩展,git,composer,npm工具
RUN apk update && apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        curl-dev \
        imagemagick-dev \
        libtool \
        libxml2-dev \
        postgresql-dev \
        sqlite-dev \
    libmcrypt-dev \
        freetype-dev \
        libjpeg-turbo-dev \
        libpng-dev \
    && apk add --no-cache \
        curl \
        git \
        imagemagick \
        mysql-client \
        postgresql-libs \
        nodejs \
        nodejs-npm \
    # 配置npm中国镜像
    && npm config set registry https://registry.npm.taobao.org \
    && pecl install imagick \
    && pecl install mcrypt-1.0.1 \
    && docker-php-ext-enable mcrypt \
    && docker-php-ext-enable imagick \
    && docker-php-ext-install \
        curl \
        mbstring \
        pdo \
        pdo_mysql \
        pdo_pgsql \
        pdo_sqlite \
        pcntl \
        tokenizer \
        xml \
        zip \
    && docker-php-ext-install -j"$(getconf _NPROCESSORS_ONLN)" iconv \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j"$(getconf _NPROCESSORS_ONLN)" gd \
    && pecl install -o -f redis \
    && rm -rf /tmp/pear \
    && docker-php-ext-enable redis

# 安装composer并允许root用户运行
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV COMPOSER_NO_INTERACTION=1
ENV COMPOSER_HOME=/usr/local/share/composer
RUN mkdir -p /usr/local/share/composer \
    && curl -o /tmp/composer-setup.php https://getcomposer.org/installer \
    && php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer --snapshot \
    && rm -f /tmp/composer-setup.* \
    # 配置composer中国全量镜像
    && composer config -g repo.packagist composer https://packagist.phpcomposer.com

# 对其他容器开放9000端口
EXPOSE 9000

 

4、php:7.4-fpm

 

FROM php:7.4-fpm

#Download PHP extensions
#ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
#RUN chmod uga+x /usr/local/bin/install-php-extensions && sync

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/

RUN DEBIAN_FRONTEND=noninteractive apt-get update -q \
    && DEBIAN_FRONTEND=noninteractive apt-get install -qq -y \
      curl \
      git  \
      zip unzip \
    && install-php-extensions \
      bcmath \
      bz2 \
      calendar \
      exif \
      gd \
      intl \
      ldap \
      memcached \
      mysqli \
      opcache \
      pdo_mysql \
      pdo_pgsql \
      pgsql \
      redis \
      soap \
      xsl \
      zip \
      sockets \
      swoole \
      yaf \
      memcached \
      mongodb \
      mcrypt \
      iconv \
      mbstring
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
    && ln -s $(composer config --global home) /root/composer
ENV PATH=$PATH:/root/composer/vendor/bin COMPOSER_ALLOW_SUPERUSER=1

 

posted @ 2022-03-07 19:00  i金少  阅读(1504)  评论(0编辑  收藏  举报