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:

  • docker exec wrong with remote docker host in Jenkins
  • Volumes mounting as folders
  • Check/connect to Redis running within docker from Java(Spring Boot) or Node.js
  • Where should I keep service files for a CoreOS cluster, and how should I load them?
  • Docker remote api pull from Docker hub private registry
  • Changing the configuration of zookeeper docker image
  • <?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 https://getcomposer.org/installer | 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?

  • Why docker exec is killing nohup process on exit?
  • Rails engine apps deployed with docker
  • Filter docker-compose output
  • What's eth0 used for in docker host machine
  • App in Docker does not update
  • How to cache the RUN npm install instruction when docker build a Dockerfile
  • 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

    extension=php_pgsql.so
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.