Unable to use phpredis with Docker. gives Redis class not found - php

I have set up php-fpm, redis, nginx and mysql. Now that I want to use php redis extension, I am getting Redis class not found error.
My php docker file:
# php-fpm
FROM php:fpm-alpine
RUN docker-php-ext-install pdo_mysql
ARG INSTALL_PHPREDIS=false
RUN if [ ${INSTALL_PHPREDIS} = true ]; then \
# Install Php Redis Extension
pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis \
;fi
CMD ["php-fpm"]
EXPOSE 9000
My docker-composer.yml:
version: '2'
services:
php-fpm:
build:
context: ./php-fpm
volumes:
- ../src:/var/www
nginx:
build:
context: ./nginx
volumes:
- ../src:/var/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/sites/:/etc/nginx/sites-available
- ./nginx/conf.d/:/etc/nginx/conf.d
ports:
- "80:80"
- "443:443"
depends_on:
- php-fpm
database:
build:
context: ./database
environment:
- MYSQL_DATABASE=mydb
- MYSQL_USER=myuser
- MYSQL_PASSWORD=secret
- MYSQL_ROOT_PASSWORD=docker
cache:
build:
context: ./redis
ports:
- "6379:6379"
I want to use redis extension in my php. Not sure what I am missing.

Related

PHP Pest (with Laravel) tests running very slow in OSX Docker

I was developing an app locally using Laravel. For testing I was using Pest and tests were running fast, really fast. That was until I decided to Dockerize my app, now tests are running pretty slow.
What it used to run in 3 seconds now it's running in over a minute.
Here's my Dockerfile:
FROM php:8.1.12-fpm
ARG uid=1000
ARG user=macgiver
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Install and enable xDebug
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install php modules required by laravel.
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Create system user to run Composer and Artisan commands.
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Install composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Set working directory
WORKDIR /var/www
USER $user
and this is my docker-compose:
version: "3.9"
services:
app:
build:
context: ./
dockerfile: Dockerfile
image: dmc
container_name: dmc-app
restart: unless-stopped
working_dir: /var/www/
depends_on:
- db
- nginx
volumes:
- ./:/var/www/
- ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
expose:
- "9003"
networks:
- dmc-net
nginx:
image: nginx:1.23.2-alpine
container_name: dmc-nginx
restart: unless-stopped
ports:
- "8000:80"
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d
networks:
- dmc-net
db:
image: mysql:8.0.31
container_name: dmc-db
restart: unless-stopped
# using 3307 on the host machine to avoid collisions in case there's a local MySQL instance installed already.
ports:
- "3307:3306"
# use the variables declared in .env file
environment:
MYSQL_HOST: ${DB_HOST}
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: abcd1234
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./docker-compose/mysql:/docker-entrypoint-initdb.d
- mysql-data:/var/lib/mysql
networks:
- dmc-net
networks:
dmc-net:
driver: bridge
volumes:
mysql-data:
Any ideas?

Why Laravel App in Docker response with 404 status code

I have a laravel application on a docker container
In my local windows development environment it works correctly. When I take the docker container to the ubuntu linux test server the index.php return 404 response code when i run docker compose up command in ubuntu terminal
docker_compose.yml
version: "3.9"
services:
#Nginx Service
webserver:
image: nginx:1.21.6-alpine
container_name: webserver-maderas
restart: unless-stopped
tty: true
ports:
- "8082:80"
- "444:443"
volumes:
- ./src:/var/www/
configs:
- source: nginx_config
target: /etc/nginx/conf.d/default.conf
networks:
- app-network
node:
image: node:16-alpine
working_dir: /var/www
container_name: node-maderas
volumes:
- ./src:/var/www
- /var/www/node_modules
configs:
- source: node_script
target: /var/www/node_start.sh
command: sh /var/www/node_start.sh
depends_on:
- app
networks:
- app-network
db:
image: mariadb:10.7.3-focal
container_name: db-maderas
restart: unless-stopped
tty: true
ports:
- "3308:3306"
environment:
MARIADB_DATABASE: ${MARIADB_DATABASE}
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
volumes:
- dbdata:/var/lib/mysql/
networks:
- app-network
# adminer:
# image: adminer
# restart: always
# ports:
# - 8080:8080
# networks:
# - app-network
app:
build:
context: .
dockerfile: Dockerfile
image: php:8.1-fpm-alpine3.14
container_name: app-maderas
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./src:/var/www/
networks:
- app-network
networks:
app-network:
name: network.local
driver: bridge
configs:
nginx_config:
file: ./nginx/conf.d/default.conf
node_script:
file: ./node/node_start.sh
volumes:
dbdata:
driver: local
Dockerfile
FROM php:8.1-fpm-alpine
WORKDIR /var/www/public
RUN apk update \
&& apk upgrade \
&& apk add --no-cache \
freetype-dev \
libjpeg-turbo-dev \
libmcrypt-dev \
libpng-dev
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install mysqli pdo pdo_mysql gd
RUN docker-php-ext-enable pdo_mysql
RUN addgroup -g 1000 -S www && adduser -u 1000 -S www -G www
COPY --chown=www:www ./src/ /var/www
USER www
EXPOSE 9000
CMD ["php-fpm"]

Ngnix server giving 502 error when using supervisor

There is problem with Docker when using supervisor . Actually server doesn't give any error . When starting supervisor emerges problems which when enter site giving 502 errors !
When uncomment follow code in image php giving error
#ENTRYPOINT ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
Follow docker.yml
services:
webapp:
build:
context: .
dockerfile: Docker/php/prod.Dockerfile
image: webapp:php
container_name: webapp
restart: always
tty: true
stdin_open: true
volumes:
- ./Docker/php/ini/volume_conf.prod.conf:/usr/local/etc/php/conf.d/volume_conf.prod.conf
- ./Docker/php/supervisor/supervisord.conf:/etc/supervisor/supervisord.conf
- ./Docker/php/supervisor/multiProductRunner.conf:/etc/supervisor/conf.d/multiProductRunner.conf
- ./Docker/php/supervisor/crawlingProductsRunner.conf:/etc/supervisor/conf.d/crawlingProductsRunner.conf
#- ./Docker/php/supervisor/start-container:/usr/local/bin/start-container
- ./source/:/var/www/html
networks:
customnetwork:
ipv4_address: 172.20.0.10
db:
build:
context: .
dockerfile: ./Docker/mysql/Dockerfile
image: mariadb
container_name: db
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: ''
MYSQL_USER: 'user'
MYSQL_PASSWORD: 'password'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- ./Docker/mysql/volume/:/var/lib/mysql
networks:
customnetwork:
ipv4_address: 172.20.0.11
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-p password" ]
retries: 3
timeout: 5s
nginx:
image: nginx:alpine
container_name: nginx
tty: true
volumes:
- ./source/:/var/www/html
- ./Docker/nginx/:/etc/nginx/conf.d/
ports:
- "9001:80"
networks:
customnetwork:
ipv4_address: 172.20.0.12
meilisearch:
image: 'getmeili/meilisearch:latest'
ports:
- '7700:7700'
volumes:
- './Docker/meilisearch/volume/:/meili_data'
networks:
customnetwork:
ipv4_address: 172.20.0.13
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--spider", "5"]
retries: 3
timeout: 5s
networks:
customnetwork:
ipam:
config:
- subnet: 172.20.0.0/16
PHP version 8.1 image file (problem is there
FROM php:8.1-fpm
# PHP extensions
RUN apt-get update
RUN apt-get install -y build-essential libssl-dev zlib1g-dev libpng-dev libjpeg-dev libfreetype6-dev
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo pdo_mysql gd
RUN apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-install zip
RUN echo 'memory_limit = -1' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini
RUN apt-get remove supervisor --yes
RUN apt-get install supervisor --yes
RUN service supervisor start
#COPY ./Docker/php/supervisor/multiProductRunner.conf /etc/supervisor/conf.d/supervisord.conf
#COPY ./Docker/php/supervisor/start-container /usr/local/bin/start-container
#RUN chmod +x /usr/local/bin/start-container
# when uncomment follow code giving error
#ENTRYPOINT ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
#EXPOSE 9000

Problem in docker images it is not starting

I made in my project nginx, mysql, phpMyadmin, encore and php images.
Just php and encore dosent work, they are successed built, but the are with red color.
The directory of the project:
that is my docker-compose.yml:
version: '3.3'
services:
database:
container_name: database
image: mysql:8.0
restart: always
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: alsbls
MYSQL_DATABASE: infoSystem
MYSQL_USER: alsbls
MYSQL_PASSWORD: alsbls
ports:
- '4306:3306'
volumes:
- ./mysql:/var/lib/mysql
php:
container_name: php
restart: always
build:
context: ./php
ports:
- '9000:9000'
volumes:
- ./app:/var/www/infoSystem
depends_on:
- database
nginx:
container_name: nginx
image: nginx:stable-alpine
restart: always
ports:
- '8080:80'
volumes:
- ./app:/var/www/infoSystem
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- database
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
restart: always
environment:
PMA_HOST: database
PMA_USER: alsbls_root
PMA_PASSWORD: alsbls_root
ports:
- "8081:81"
encore:
container_name: encore
restart: always
build:
context: ./php
volumes:
- ./:/var/www/html
That is my Dockerfile:
FROM php:8.0-fpm
RUN apt update \
&& apt install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip \
&& docker-php-ext-install intl opcache pdo pdo_mysql \
&& pecl install apcu \
&& docker-php-ext-enable apcu \
&& docker-php-ext-configure zip \
&& docker-php-ext-install zip
WORKDIR /var/www/infoSystem
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN curl -sS https://get.symfony.com/cli/installer | bash
RUN mv /root/.symfony/bin/symfony /usr/local/bin/symfony
RUN git config --global user.email "devojob97#gmail.com" \
&& git config --global user.name "alsbls"
FROM node:12.10.0
WORKDIR /var/www/html
COPY entrypoint.sh /usr/local/bin/entrypoint
RUN ["chmod", "+x", "/usr/local/bin/entrypoint"]
ENTRYPOINT ["/usr/local/bin/entrypoint"]
USER node
that is the entrypoint.sh in the same dir of Dockerfile:
#!/bin/bash
# Prevent container from shutting down
while true; do sleep 3600; done
I didn't receive any error message on the terminal.
Maybe some one now the issues.
Best regards
I saw in the docker log of the encore image the following error:
standard_init_linux.go:190: exec user process caused "no such file or directory" - Docker
And then I tried to use the following command outside of the container:
dos2unix your-file.sh
This tutorial helped me to solve it:

How to insert dockerised cron process in a docker-compose built LEMP stack?

I have a LEMP stack which is built by this docker-compose file:
cadvisor:
image: google/cadvisor:latest
container_name: lemp_cadvisor
ports:
- "8080:8080"
volumes:
- "/:/rootfs:ro"
- "/var/run:/var/run:rw"
- "/sys:/sys:ro"
- "/var/lib/docker/:/var/lib/docker:ro"
base:
build: ./base
container_name: lemp_base
volumes:
- /home/core/server-lemp/www/:/var/www/:rw
phpmyadmin:
build: ./phpmyadmin
container_name: lemp_phpmyadmin
links:
- base
volumes:
- /var/www/phpmyadmin
- ./phpmyadmin/var/www/phpmyadmin/config.inc.php:/var/www/phpmyadmin/config.inc.php:rw
mariadb:
build: ./mariadb
container_name: lemp_mariadb
environment:
- MYSQL_ROOT_PASSWORD=pwd
links:
- base
volumes:
- /var/run/mysqld
- /home/core/server-lemp/mariadb/:/var/lib/mysql/:rw
- ./mariadb/etc/mysql/my.cnf:/etc/mysql/my.cnf:ro
ffmpeg:
build: ./ffmpeg
container_name: lemp_ffmpeg
links:
- base
volumes:
- /usr/ffmpeg
cron:
build: ./cron
container_name: lemp_cron
links:
- base
volumes:
- /etc/cron.weekly
- /etc/cron.d
- /etc/cron.hourly
- /etc/cron.daily
- /etc/cron.monthly
php:
build: ./php
container_name: lemp_php
links:
- base
volumes:
- /var/run/php-fpm
- ./php/usr/local/php7/etc/php-fpm.conf:/usr/local/php7/etc/php-fpm.conf:ro
- ./php/usr/local/php7/etc/php.ini:/usr/local/php7/etc/php.ini:ro
- ./php/usr/local/php7/etc/php-fpm.d/www.conf:/usr/local/php7/etc/php-fpm.d/www.conf:ro
volumes_from:
- base
- phpmyadmin
- mariadb
- ffmpeg
- cron
nginx:
build: ./nginx
container_name: lemp_nginx
links:
- base
ports:
- "80:80"
- "443:443"
volumes:
- /var/cache/nginx
- ./nginx/etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
volumes_from:
- php
My ./cron/Dockerfile looks like this:
# Lanti/lempCron
#
# VERSION 1.0.0
FROM lemp_base:latest
MAINTAINER XY <info#domain.com>
LABEL Description="Cron" Vendor="XY" Version="1.0"
RUN apt-get -y update && apt-get -y dist-upgrade \
&& apt-get -y install \
cron
RUN rm -rf /var/lib/apt/lists/*
CMD ["cron", "-f"]
When in a Wordpress install I inspecting running cron jobs with WP Crontrol plugin, I got the following error message:
There was a problem spawning a call to the WP-Cron system on your site.
This means WP-Cron events on your site may not work. The problem was:
Failed to connect to 127.0.0.1 port 80: Connection refused
I assume because of the same error that causing this, the Cache Purge option in the Nginx-helper plugin also not working.
Wordpress is presumably running in your 'php' container, and the "wp-cron" function is presumably working there. Although it is "cron-like", it is actually part of Wordpress.
You have defined no ports for your `php' container, so it appears that you need to update your Docker networking so that wp-contain can access port 80 on the correct host.

Categories