Reputation: 2241
I'm trying to set up my docker with php app (Symfony 3).
Everything seems to be fine but, Symfony can't connect to mysql.
I have the error:
Uncaught PHP Exception Doctrine\DBAL\Exception\DriverException: "An exception occurred in driver: could not find driver"
My docker-compose.yaml
file is:
version: '3'
services:
app:
image: car-rental
ports:
- "8888:80"
links:
- php
- db
volumes:
- ./.code:/var/www/html
depends_on:
- db
php:
image: php:7.1-fpm
volumes:
- ./.code:/var/www/html
db:
image: mysql:5.7
volumes:
- mysql-data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: rental
volumes:
mysql-data:
Upvotes: 0
Views: 1333
Reputation: 60164
As mention on the docker hub of php you can see by default it contain only redis redis xdebug is enabled.
Some extensions are not provided with the PHP source, but are instead available through PECL. To install a PECL extension, use pecl install to download and compile it, then use docker-php-ext-enable to enable it.
You can use the same docker compose file just run a command on container boot up
php:
image: php:7.1-fpm
command:docker-php-ext-install mysqli
volumes:
- ./.code:/var/www/html
Ater installation you can check
php -m
These are default modules in the latest docker images that you pulled.
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
Upvotes: 3
Reputation: 15696
This error (could not find driver
) means, that your PHP doesn't have pdo_mysql
module loaded.
You need to enable it or install first if it's not installed yet.
Upvotes: 1