无法在Docker中使用phpredis。 没有找到Redis类

I have set up php-fpm, redis, nginx and mysql. Now that I want to use php redis extension, I am getting Redis class not found error.

my php docker file

# php-fpm
FROM php:fpm-alpine

RUN docker-php-ext-install pdo_mysql

ARG INSTALL_PHPREDIS=false
RUN if [ ${INSTALL_PHPREDIS} = true ]; then \
    # Install Php Redis Extension
    pecl install -o -f redis \
    &&  rm -rf /tmp/pear \
    &&  docker-php-ext-enable redis \
;fi

CMD ["php-fpm"]

EXPOSE 9000

My docker-composer.yml

version: '2'

services: 
    php-fpm:
        build:
            context: ./php-fpm
        volumes:
          - ../src:/var/www
    nginx:
        build:
            context: ./nginx
        volumes:
            - ../src:/var/www
            - ./nginx/nginx.conf:/etc/nginx/nginx.conf
            - ./nginx/sites/:/etc/nginx/sites-available
            - ./nginx/conf.d/:/etc/nginx/conf.d
        ports:
            - "80:80"
            - "443:443"
        depends_on:
            - php-fpm

    database:
        build:
            context: ./database
        environment:
            - MYSQL_DATABASE=mydb
            - MYSQL_USER=myuser
            - MYSQL_PASSWORD=secret
            - MYSQL_ROOT_PASSWORD=docker

    cache:
        build:
            context: ./redis
        ports:
            - "6379:6379"

I want to use redis extension in my php. Not sure what I am missing.

Thanks in advance.

douchensou6969
douchensou6969 谢谢。我能够解决它。php不会默认启用redis。我不得不在phpdockerfile中添加命令并再次构建它。
一年多之前 回复
dongziche8030
dongziche8030 我想我们需要一些额外的上下文(比如你输入的命令,确切的错误等)能够帮助你
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问