0

I have Dockerfile to build my laravue project. this is my Dockerfile

FROM composer:2.0 as vendor

WORKDIR /app

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

RUN composer install \
    --no-interaction \
    --no-plugins \
    --no-scripts \
    --no-dev \
    --prefer-dist

COPY . .
RUN composer dump-autoload

#
# Frontend
#
FROM node:14.21.3-buster as frontend

WORKDIR /app

RUN apt-get update && apt-get install -y git
RUN git config --global url."https://".insteadOf git://

COPY artisan package*.json webpack.mix.js webpack.config.js .babelrc ./

RUN npm cache clean --force && npm install

COPY resources/js ./resources/js
COPY resources/sass ./resources/sass

RUN npm run production


#
# Application
#
FROM php:7.4-fpm-alpine

WORKDIR /app

# Install PHP dependencies
RUN apk add libxml2-dev libpq-dev \
&& apk add --no-cache redis \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo pdo_pgsql opcache

# Copy Frontend build
COPY --from=frontend /app/public/js/ ./public/js/
COPY --from=frontend /app/public/fonts/ ./public/fonts/
COPY --from=frontend /app/public/mix-manifest.json ./public/mix-manifest.json

# Copy Composer dependencies
COPY --from=vendor /app/vendor/ ./vendor/
# COPY . .

RUN mkdir -p /usr/src/php/ext/redis; \
    curl -fsSL https://pecl.php.net/get/redis-5.3.7 --ipv4 | tar xvz -C "/usr/src/php/ext/redis" --strip 1; \
    docker-php-ext-install redis;

CMD php artisan serve --host=0.0.0.0 --port=8000
EXPOSE 8000


This is my .env file to configure Redis

REDIS_HOST=redis-app
REDIS_PASSWORD=null
REDIS_PORT=6379

And I have Redis running on container and connect to specific network. and also my project container is connected to the same network as Redis.

When I try to access the application via web browser I get an error because the php-redis extension cannot connect to redis-app, it always connects to localhost enter image description here

I can fix this issue by running redis-server on my project container using this command

redis-server --daemonize yes

My expected result is I want that php-redis extension on my project container connect to redis-app not localhost without running redis-server on my project container. Thank you for any help!

noqriz
  • 11
  • 1
  • I think you try the link mentioned below: https://stackoverflow.com/questions/31369867/how-to-install-php-redis-extension-using-the-official-php-docker-image-approach – Soheb Aug 16 '23 at 04:46

0 Answers0