I have a Dockerfile:
FROM php:7-fpm
RUN apt-get update \
&& apt-get install -y --no-install-recommends libpq-dev \
&& docker-php-ext-install mysqli pdo_pgsql pdo_mysql
Then I have in my docker-compose.yml file:
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./frontend:/var/www/html
- ./api:/var/www/html/api
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
links:
- php
mysql:
image: mariadb
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=example
volumes:
- ./database:/var/lib/mysql
php:
image: php:7-fpm
volumes:
- ./frontend:/var/www/html
- ./api:/var/www/html/api
links:
- mysql
Then In my PHP Code I have:
<?php
$servername = "localhost";
$username = "root";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=example", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
Which when I go to connect to my database I get:
Connection failed: could not find driver
How would I download the PDO driver using this docker setup?