6

I'm setting a deploy of laravel to kubernetes and want to have redis.

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)

I expected to add the php redis to the php-fpm container, any ideas?

here the actual php /Dockerfile

#
# 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 \
    && apk add --no-cache \
        curl \
        git \
        mysql-client \
    && docker-php-ext-install \
        mbstring \
        pdo \
        pdo_mysql \
        tokenizer \
        bcmath \
        opcache \
        xml \
    && apk del -f .build-deps \
    && 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"]

and the nginx /Dockerfile

FROM nginx:stable-alpine

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

COPY public /var/www/html/public
WORKDIR /var/www/html/public

finally the nginx default /conf.d

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;
    }
}

2 Answers 2

9

Since you are using official PHP docker image, you can install php-redis extension via PECL:

RUN pecl install redis \
    && docker-php-ext-enable redis

Simple as that!

You can learn more about installing PHP extensions from official PHP docker docs (in case of php-redis, installing PECL extensions).

So in your case, RUN command can look something like this:

# Your PHP Dockerfile
RUN apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        curl \
        libtool \
        libxml2-dev \
    && apk add --no-cache \
        curl \
        git \
        mysql-client \
    && pecl install redis \     # install redis extension via PECL
    && docker-php-ext-install \
        mbstring \
        pdo \
        pdo_mysql \
        tokenizer \
        bcmath \
        opcache \
        xml \
    && apk del -f .build-deps \
    && docker-php-ext-enable \
       pdo_mysql \
       redis                    # don't forget to enable redis extension
Sign up to request clarification or add additional context in comments.

1 Comment

If using an Alpine based image, you will need an extra line before the PECL installation: apk --no-cache add pcre-dev ${PHPIZE_DEPS}
2

Update for alpine php 7.3.5

RUN apk add --no-cache pcre-dev $PHPIZE_DEPS \
        && pecl install redis \
        && docker-php-ext-enable redis.so

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.