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-compose + external container
  • Fail when start a new container with elasticsearch 5.0
  • XDebug could not open the remote debug file '/var/log/xdebug.log' while reading response header from upstream
  • How to change the default location for “docker create volume” command?
  • assign port docker issue
  • Failure of building Jenkins 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 | 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?

  • Generate all locales in a docker image
  • Can't connect with BOLT to a docker Neo4j
  • VS 2017 Add > Docker Support breaks build - “CleanWorkspace” task failed unexpectedly (console app)
  • Vagrant docker provisioner command
  • Specify bolt port for a neo4j docker container
  • chef-solo not applying recipe changes
  • 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.