Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstdmstd's avatar

How to fix Doctrine\\DBAL\\Driver\\PDOException error in docker with laravel 5 app

Hello! I have problem with running my laravel 5.5/postgres app in docker asp I see error in my logs

could not find driver {"exception":"[object] (Doctrine\DBAL\Driver\PDOException

usually to fix this error I have to run in console of my ubuntu :

composer require doctrine/dbal

I have in file docker-compose.yml :

...
    lprods_composer:
        image: composer:1.6
        container_name: lprods_composer_container
        volumes:
            - ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
        working_dir: ${APP_PTH_CONTAINER}
        command: composer install  --ignore-platform-reqs

Which way is to salve it? I suppose I have to set this option in my docker-compose.yml file ?

Thanks!

0 likes
4 replies
bobbybouwmann's avatar

I'm not sure why your stuff it not working because I have not enough information right now. Normally you would run composer require doctrine/dbal locally and then put the new composer.json and composer.lock in the container so you won't have to run composer require on your server or in this case your container.

Since you use containers you don't have a shared state like a server. If you destroy the container and new it up you endup without the doctrine/dbal again!

mstdmstd's avatar

Do you mean that before setting docker container the composer.json ALREADY MUST HAVE referance to doctrine/dbal ?

It does not any "doctrine/dbal" or "doctrine" line.

But looking at my composer.lock I see lines :

...
            "require-dev": {
                "aws/aws-sdk-php": "~3.0",
                "doctrine/dbal": "~2.5",
                ...
            },
...
        {
            "name": "doctrine/dbal",
            "version": "v2.5.13",
            "source": {
                "type": "git",
                "url": "https://github.com/doctrine/dbal.git",
                "reference": "729340d8d1eec8f01bff708e12e449a3415af873"
            },
...
            "require": {
                "doctrine/dbal": "~2.4",
...

Have I to add to

    "require": {

block of my composer.json

line :
         "doctrine/dbal": "~2.5",

and rebuild the docker ?

I wonder why the definition of doctrine/dbal is not in my composer.json, as far as I remember I installed it in command line :

composer require doctrine/dbal

How correctly to salve it?

mstdmstd's avatar

In composer.json of the project I added "doctrine/dbal": "~2.5" declaration under "require" and now this file is :

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "barryvdh/laravel-debugbar": "^2.3",
        "graham-campbell/markdown": "^8.0",
        "intervention/image": "^2.3",
        "khill/lavacharts": "3.0.*",
        "laravel/framework": "5.5.*",
        "laravel/socialite": "^3.0",
        "laravel/tinker": "~1.0",
        "laravelcollective/html": "^5.4.0",
        "nwidart/laravel-modules": "^2.2",
        "doctrine/dbal": "~2.5",
        "wboyz/laravel-enum": "^0.2.1"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~6.0",
        "stolz/laravel-html-tidy": "^0.1.1",
        "xethron```
/migrations-generator": "^2.0",
        "filp/whoops" : "~2.0" 
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\": "app/",
            "Modules\": "Modules/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\Foundation\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\Foundation\ComposerScripts::postUpdate",
            "php artisan optimize"
        ],

        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]

    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

I rebuilded the app, cleared the cache, but running the app I got errors in log file :

[2018-11-01 12:40:09] local.ERROR: could not find driver {"exception":"[object] (Doctrine\DBAL\Driver\PDOException(code: 0): could not find driver at /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47, PDOException(code: 0): could not find driver at /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43)
[stacktrace]
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(64): Doctrine\DBAL\Driver\PDOConnection->__construct('pgsql:host=127....', 'postgres', '1', Array)
#1 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(43): Illuminate\Database\Connectors\Connector->createPdoConnection('pgsql:host=127....', 'postgres', '1', Array)
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/PostgresConnector.php(33): Illuminate\Database\Connectors\Connector->createConnection('pgsql:host=127....', Array, Array)
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php(183): Illuminate\Database\Connectors\PostgresConnector->connect(Array)
#4 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}()
...
  1. Was my declaration invalid ?
  1. I tried to run in my container box but got :
# composer require doctrine/dbal
bash: composer: command not found

I suppose that in my container box I can try to install composer , but is it proper way ?

What would you advice ?

mstdmstd's avatar

Sorry, I still search for decision... No ideas?

Please or to participate in this conversation.