Reputation: 111
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?
Upvotes: 1
Views: 2236
Reputation: 111
I turned out to be a problem in the 'php-worker' container. I hadn't installed pdo_mysql here. Now everything works fine!
Upvotes: 2
Reputation: 1051
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
.
Upvotes: 2