2

I have the following docker.yml file

version: "3"
services:
  wwww:
    build: .
    ports:
      - "8888:80"
    volumes:
      - "./src:/var/www/html/"
    networks:
      - default
  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example

  adminer:
    image: adminer
    restart: always
    ports:
      - 8060:8080

and the docker file for php is

FROM php:7.2-apache
RUN docker-php-ext-install mysqli pdo pdo_mysql

I checked with phpinfo() and the pdo driver is enabled for sqlite.

Even when I do docker-compose I get the following warning warning: pdo (pdo.so) is already loaded!

However, I still get an exception that pdo is not found.

Is there anything that I am missing ?

The exact error is

Fatal error: Uncaught PDOException: could not find driver in /var/www/html/index.php:5 

Stack trace: 
#0 /var/www/html/index.php(5): PDO->__construct('mysql:host=127....', 'root', 'example') 
#1 {main} thrown in /var/www/html/index.php on line 5
Christoph Kluge
  • 1,947
  • 8
  • 23
Orestis uRic
  • 347
  • 1
  • 6
  • 11

1 Answers1

2

Hello Orestis and welcome to stack overflow! I've run your Dockerfile and initiated a PDO connection and I get a correct behavior.

Are you running an outdated image of a previous version of your Dockerfile? Can you try to rebuild your image with the Dockerfile above? According to your docker-compose.yml you should be able to use this command inside your project:

docker-compose build wwww

Here is my quick test with your Dockerfile, which seems ok to me:

With pdo_mysql enabled (correct behavior because there is no server running):

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] Connection refused in /var/www/html/test.php:3
Stack trace:
#0 /var/www/html/test.php(3): PDO->__construct('mysql:host=127....', 'user', 'password')
#1 {main}
  thrown in /var/www/html/test.php on line 3

With pdo_mysql disabled (correct because I remove the extension manually):

Fatal error: Uncaught PDOException: could not find driver in /var/www/html/test.php:3
Stack trace:
#0 /var/www/html/test.php(3): PDO->__construct('mysql:host=127....', 'user', 'password')
#1 {main}
  thrown in /var/www/html/test.php on line 3

Please let me know if rebuilding your image fixed the issue.

Christoph Kluge
  • 1,947
  • 8
  • 23