进入容器内部

docker exec -it 474d87735499 /bin/bash

可以先看看有没有Redis扩展

php -m

安装Redis扩展

pecl install -o -f redis

修改配置php.ini

先说下查找php.ini的几个方法 1、直接在页面查看,echo phpinfo();

Configuration File (php.ini) Path/usr/local/etc/php
Loaded Configuration File/usr/local/etc/php/php.ini
Scan this dir for additional .ini files/usr/local/etc/php/conf.d

2、用命令查看所以.ini结尾的文件位置

root@474d87735499:/tmp# php --ini Configuration File (php.ini) Path: /usr/local/etc/php Loaded Configuration File:         /usr/local/etc/php/php.ini Scan for additional .ini files in: /usr/local/etc/php/conf.d Additional .ini files parsed:      /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini, /usr/local/etc/php/conf.d/docker-php-ext-redis.ini, /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini 3、搜索php目录

root@474d87735499:/tmp# whereis php php: /usr/local/bin/php /usr/local/etc/php /usr/local/lib/php /usr/local/php 找到配置文件就可以修改了

配置文件目录/usr/local/etc/php,复制一个

root@474d87735499:/# cd /usr/local/etc/php root@474d87735499:/usr/local/etc/php# ls conf.d  php.ini-development  php.ini-production root@474d87735499:/usr/local/etc/php# cp php.ini-development php.ini root@474d87735499:/usr/local/etc/php# ls conf.d  php.ini  php.ini-development  php.ini-production

#编辑配置文件,在后面添加:extension=redis.so

root@474d87735499:/usr/local/etc/php# vim php.ini extension=redis.so

4、cli下可以直接查看安装是否成功

php -m | grep redis 5、fpm需要重启容器才能生效

docker restart php容器id或名称