使用Docker构建PHP7.4镜像,并添加redis,zip模块等

默认的官方php docker镜像是不带redis扩展的,甚至连gd、opcache、pdo_mysql等扩展也要自己配置。

修改镜像源文件,sources.list内容如下:

deb http://mirrors.aliyun.com/debian/ buster main contrib non-free
deb-src http://mirrors.aliyun.com/debian/ buster main contrib non-free
 
deb http://mirrors.aliyun.com/debian-security/ buster/updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian-security/ buster/updates main contrib non-free
 
deb http://mirrors.aliyun.com/debian/ buster-updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian/ buster-updates main contrib non-free
 
deb http://mirrors.aliyun.com/debian/ buster-backports main contrib non-free
deb-src http://mirrors.aliyun.com/debian/ buster-backports main contrib non-free

以下是Dockerfile文件内容:

FROM php:7.4-fpm

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

COPY  sources.list /etc/apt/sources.list

RUN apt-get update && echo y| apt-get install \
    --no-install-recommends libfreetype6-dev libjpeg62-turbo-dev libpng-dev zlib1g=1:1.2.11.dfsg-1+deb10u2 zlib1g-dev libzip-dev \
    && rm -r /var/lib/apt/lists/* \
    && docker-php-ext-configure gd \
    && docker-php-ext-install -j$(nproc) gd opcache pdo_mysql gettext sockets zip
 
RUN pecl install redis \
    && docker-php-ext-enable redis

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

构建镜像命令:

docker build -t new_php:7.4 .

然后参考这篇文章使用:https://www.cnblogs.com/hahaha111122222/p/17628951.html

访问效果



查看依赖包

# php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
SimpleXML
sockets
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

若是想安装其他模块, 需要先在这个网站上查询一下,确定有安装包的话,修改一下Dockerfile文件,再进行安装
http://pecl.php.net/package-stats.php

模块依赖配置文件路径:/usr/local/etc/php/conf.d

php配置文件路径:

posted @ 2023-08-14 17:08  哈喽哈喽111111  阅读(992)  评论(0编辑  收藏  举报