Check if you have the vendor directory in the project directory inside the container to see if your correctly mapped your volumes.
May 3, 2022
7
Level 1
Laravel in Docker: Class "PDO" not found
Hello developers,
I try to run Laravel with Docker but when I run php artisan migrate I get the error Class "PDO" not found.
This is docker-compose file that I use:
version: 3.4
services:
php-apache-environment:
container_name: php-apache
build:
context: .
dockerfile: Dockerfile
depends_on:
- db
volumes:
- ./www:/var/www/html:Z
ports:
- 8000:80
db:
container_name: db
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: zqw36vuahnrk
MYSQL_DATABASE: laravel-mvc
MYSQL_USER: laravel-user
MYSQL_PASSWORD: dw3kngbtd773
ports:
- 9906:3306
volumes:
- dbdata:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
restart: always
environment:
PMA_HOST: db
depends_on:
- db
With this Dockerfile
FROM php:8.1-apache
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN apt-get update && apt-get upgrade -y
I run the command php artisan migrate on the host.
When I run php artisan migrate inside the container I get the error Illuminate\Database\QueryException SQLSTATE[HY000] [2002] No such file or directory.
Do somebody have an idea what I could do wrong / what I can do?
Please or to participate in this conversation.