When i tried to run php artisan migrate within my running container i got error like could not find driver that i think not properly installed postgres i included the code and error below help me to find this.
My docker file
FROM php:fpm-alpine
RUN set -ex \
&& apk --no-cache add \
postgresql-dev
RUN docker-php-ext-install pdo pgsql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
COPY . .
RUN composer install
WORKDIR /var/www/html
CMD php artisan serve --host=0.0.0.0 --port=8080
EXPOSE 8080
My docker-compose.yml file
version: '3'
services:
php_3:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/var/www/html
ports:
- "8080:8080"
postgres_3:
image: postgres:12.3-alpine
restart: unless-stopped
tty: true
ports:
- "5431:5432"
volumes:
- ./docker/postgres:/var/lib/postgresql/data
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: lara_3
.env file
DB_CONNECTION=pgsql
DB_HOST=postgres_3
DB_PORT=5432
DB_DATABASE=lara_3
DB_USERNAME=root
DB_PASSWORD=root
My containers are running and laravel also running but if i tried to migrate tables with my docker container docker-compose exec php_3 sh
i am getting error like this.
/var/www/html # php artisan migrate
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:703
699▕ // If an exception occurs when attempting to run a query, we'll format the error
700▕ // message to include the bindings with SQL, which will make this exception a
701▕ // lot more helpful to the developer instead of just the database's errors.
702▕ catch (Exception $e) {
➜ 703▕ throw new QueryException(
704▕ $query, $this->prepareBindings($bindings), $e
705▕ );
706▕ }
707▕ }
33 vendor frames
34 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Please help me to fix this.
CodePudding user response:
Run command and install postgres extension :
docker-php-ext-install pdo_pgsql pgsql