Docker Postgres – PDO exception get

I am new with Docker, but I am in trouble, I’ve get this error always:

Fatal error: Uncaught PDOException: could not find driver in /var/www/html/index.php:16 Stack trace: #0 /var/www/html/index.php(16): PDO->__construct('pgsql:host=loca...', 'project', 'project') #1 {main} thrown in /var/www/html/index.php on line 16

Here is my index.php:

  • Execute multiple commands from shell to docker container
  • Two docker container need volumes from each other
  • CoreOS + docker issues with losetup
  • Golang High GC pause times on docker/kubernets
  • Docker Private Registry - push to 'insecure-registry' still complains about 'unknown authority'
  • Automated Build - image without source files
  • <?php
            $database   = $user = $password = "project";
            $host       = "localhost";
            $connection = new PDO("pgsql:host={$host};dbname={$database};charset=utf8", $user, $password);
            $query      = $connection->query("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_TYPE='BASE TABLE'");
            $tables     = $query->fetchAll(PDO::FETCH_COLUMN);

    And this is how my Dockerfile looks:

    FROM php:7.0-fpm
    RUN apt-get update && apt-get install -y
    RUN apt-get install git
    RUN docker-php-ext-install mbstring mcrypt opcache
    RUN docker-php-ext-configure pgsql -with-pgsql=/usr/include/postgresql/
    RUN docker-php-ext-install pgsql pdo_pgsql
    RUN curl -sS | php
    RUN mv composer.phar /usr/local/bin/composer

    However I have that feeling that Dockerfile does not run, it is too fast when I run the docker-compose up -d command.

    Somebody knows why I get the PDOException?

  • Dockerfile: RUN command with special parameters
  • Docker - `top` like real time metrics in command line
  • Why is docker volume create and rm not symmetrical?
  • What is the benefit of reverse proxy if we can expose to port 80 directly?
  • Electron inside Docker with X11 Forwarding - No Protocol Specified
  • TravisCI build succeeds even when tests fail
  • One Solution collect form web for “Docker Postgres – PDO exception get”

    If the package is installed, you need to enable the module in php.ini

    Add the following line to php.ini file
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.