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)
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;
}
}
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With