How to install php-redis extension using the official PHP Docker image approach?

Since Redis is not a part of the built-in extensions in "php-src", the "docker-php-ext-install" command cannot be used for its installation. Instead, PECL should be used.

Here is an example of how you can use PECL to install the php-redis extension:

FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
    redis-server \
    && pecl install redis \
    && docker-php-ext-enable redis

This will install the php-redis extension in the image. You can also use pecl install redis instead of docker-php-ext-install redis.

You can add this to your Dockerfile and then build and run a container using this image, the php-redis extension will be installed and enabled.