<p>I'm setting a deploy of  laravel to kubernetes and want to have redis.</p>

<p>Actually i have a Dockerfile for nginx and another one for php-fpm-alpine and all the kubernetes yaml files(the ingress with tls, deployments and services)</p>

<h3>I expected to add the php redis to the php-fpm container, any ideas?</h3>

<p>here the actual php /Dockerfile</p>

<pre><code>#
# PHP Dependencies
#
FROM composer:1 as vendor

COPY database/ database/
COPY composer.json composer.json
COPY composer.lock composer.lock

RUN composer install \
    --ignore-platform-reqs \
    --no-interaction \
    --no-plugins \
    --no-scripts \
    --prefer-dist

#
# Application
#
FROM php:fpm-alpine
RUN apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        curl \
        libtool \
        libxml2-dev \
    &amp;&amp; apk add --no-cache \
        curl \
        git \
        mysql-client \
    &amp;&amp; docker-php-ext-install \
        mbstring \
        pdo \
        pdo_mysql \
        tokenizer \
        bcmath \
        opcache \
        xml \
    &amp;&amp; apk del -f .build-deps \
    &amp;&amp; docker-php-ext-enable pdo_mysql

WORKDIR /var/www/html

COPY . /var/www/html
COPY --from=vendor /app/vendor/ /var/www/html/vendor/
COPY .env.example /var/www/html/.env

RUN chown -R root:www-data . 

EXPOSE 9000

CMD ["php-fpm"]
</code></pre>

<p>and the nginx /Dockerfile</p>

<pre><code>FROM nginx:stable-alpine

ADD default.conf /etc/nginx/conf.d/default.conf

COPY public /var/www/html/public
WORKDIR /var/www/html/public
</code></pre>

<p>finally the nginx default /conf.d</p>

<pre><code>server {
    listen 80;

    index index.php index.html;
    root /var/www/html/public;

    client_max_body_size 32M;

    location / {
        try_files $uri /index.php?$args;
    }

    location ~ \.php$ {
    fastcgi_pass   php:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
    }
}
</code></pre>

madwyatt
<p>Since you are using official PHP docker image, you can install php-redis extension via PECL:</p>

<pre><code>RUN pecl install redis \
    &amp;&amp; docker-php-ext-enable redis
</code></pre>

<p>Simple as that! </p>

<p>You can learn more about <a href="https://github.com/docker-library/docs/tree/master/php#how-to-install-more-php-extensions" rel="noreferrer">installing PHP extensions</a> from official PHP docker docs (in case of <code>php-redis</code>, <a href="https://github.com/docker-library/docs/tree/master/php#pecl-extensions" rel="noreferrer">installing PECL extensions</a>).</p>

<p>So in your case, <code>RUN</code> command can look something like this:</p>

<pre><code># Your PHP Dockerfile
RUN apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        curl \
        libtool \
        libxml2-dev \
    &amp;&amp; apk add --no-cache \
        curl \
        git \
        mysql-client \
    &amp;&amp; pecl install redis \     # install redis extension via PECL
    &amp;&amp; docker-php-ext-install \
        mbstring \
        pdo \
        pdo_mysql \
        tokenizer \
        bcmath \
        opcache \
        xml \
    &amp;&amp; apk del -f .build-deps \
    &amp;&amp; docker-php-ext-enable \
       pdo_mysql \
       redis                    # don't forget to enable redis extension
</code></pre>
