1

I'm new to using Redis. I'm running Laravel, MariaDB, and Redis in Docker. I can't seem to get redis to work properly. I get the following error in Laravel Horizon:

PDOException: could not find driver in /var/www/api/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:46

My guess is that the code is being executed inside the redis container, that has no access to the PHP container.

This is my docker-compose.yml:

# Web server
nginx:
    image: nginx:latest
    restart: always
    links:
    - socketio-server
    ports:
    - "3000:3001"
    - "8081:80"
    volumes:
    - ./api:/var/www/api
    - ./docker/nginx/conf.d/:/etc/nginx/conf.d
    - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
    links:
    - php

# PHP
php:
    build: ./docker/php-fpm
    volumes:
    - ./api:/var/www/api
    links:
    - mariadb

# Redis
redis:
    image: redis:latest
    depends_on:
    - php
    expose:
    - "6379"

# Database
mariadb:
    image: mariadb:latest
    restart: always
    ports:
    - "3306:3306"
    volumes:
    - ./database/mariadb/:/var/lib/mysql

# PHP workers
php-worker:
    build:
    context: ./docker/php-worker
    args:
        - PHP_VERSION=7.2
        - INSTALL_PGSQL=false
    volumes:
    - ./:/var/www
    - ./docker/php-worker/supervisor.d:/etc/supervisor.d
    extra_hosts:
    - "dockerhost:10.0.75.1"
    links:
    - redis

Anyone any ideas?

2 Answers 2

2

Your assumption that the containers don't have access to each other is correct.

Your PHP container executes the PHP code, so it must have access to the redis container and the mariadb container in order to use them. You do this by adding them to the links array. I see you have already done this for mariadb, but you should add redis as well.

# PHP
php:
    build: ./docker/php-fpm
    volumes:
    - ./api:/var/www/api
    links:
    - mariadb
    - redis

By adding redis to the links array, you can access it in your PHP container with the hostname redis.

Sign up to request clarification or add additional context in comments.

4 Comments

I thought it worked... but unfortunately it doesn't. I fired the wrong event. I still get the same error. Even if I install php inside of the redis container it doesn't work.
What credentials are you using to connect to redis? Are you using host = redis and port = 6379?
Yes I'm using those. I can add things to the queue, but when they get executed (and need to connect to a database) they crash.
I figured it out. It was the 'php-worker' container that needed pdo_mysql to be installed.
2

I turned out to be a problem in the 'php-worker' container. I hadn't installed pdo_mysql here. Now everything works fine!

1 Comment

How did you install it?

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.