Skip to content
Advertisement

“PDOException: could not find driver” inside docker container where PDO modules exist

I want to run php-fpm in a docker container, but get an error message after starting the container:

Fatal error: Uncaught PDOException: could not find driver.

I use php7.4 with event engine and a postgres database in a separate container (I use docker-compose to start them all) and are working on ubuntu20.04.

The weird thing is: My collegues installed the same stuff without having this error, so the error cannot come from an incorrect docker file.

What I tried so far:

  • I can connect to the database with psql from the shell.
  • I printed out all modules that are loaded in the container, and they include pdo and pdo_pgsql.

The error refers to this method:

JavaScript

I checked pdo.dns, pdo.user and pdo.pwd, they are all correct. I defined DNS via

JavaScript

The docker file includes

JavaScript

Advertisement

Answer

It was the DNS string, the quotation marks are wrong. It works with this:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement