Php Docker mysql找不到驱动程序
我正在尝试在容器中运行laravel应用程序,但在迁移中找不到驱动程序。 Laravel 8、mysql 8、php 8 docker composePhp Docker mysql找不到驱动程序,php,laravel,docker,docker-compose,mysql-connector,Php,Laravel,Docker,Docker Compose,Mysql Connector,我正在尝试在容器中运行laravel应用程序,但在迁移中找不到驱动程序。 Laravel 8、mysql 8、php 8 docker compose version: "3.9" services: #PHP Service app: build: context: . dockerfile: Dockerfile container_name: app restart: unless-stopped tty:
version: "3.9"
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:latest
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "8005:80"
- "8006:443"
volumes:
- ./:/var/www
- ./docker/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#Mariadb Service
db:
image: mysql
container_name: db
restart: unless-stopped
tty: true
environment:
MYSQL_DATABASE: test
MYSQL_ROOT_PASSWORD: test
SERVICE_TAGS: dev
SERVICE_NAME: db
volumes:
- dbdata:/var/lib/mysql1
- ./docker/sqldb/db.cnf:/etc/sqldb/db.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
Dockerfile
FROM php:fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Copy existing application directory contents
COPY . /var/www
# Set working directory
WORKDIR /var/www
# Give permissions
RUN chown -R www-data:www-data .
RUN find . -type f -exec chmod 664 {} \;
RUN find . -type d -exec chmod 775 {} \;
RUN chgrp -R www-data storage bootstrap/cache
RUN chmod -R ug+rwx storage bootstrap/cache
RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN docker-php-ext-install mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Expose port 9000 and start php-fpm server
EXPOSE 9000
环境署署长
它缺少一些扩展,我不知道是什么,也许我正在安装与PHP8不兼容的pdo?正确创建了用户和数据库
错误
注意:我在stackoverflow上尝试了许多不同答案的解决方案
谢谢大家!
phpinfo()具有PDO(启用sqlite)、PDO_sqlite(3.27.2)和mysqlnd 8.0.6
这是我能看到的唯一的db驱动程序,可能与我使用docker compose添加的local.ini有关
这是local.ini
upload_max_filesize=40M
post_max_size=40M
# tried adding extension=php_pdo_mysql.so, no luck
您能否通过以下示例之一确认驱动程序是否已实际安装来帮助我们?正如引用的注释中所指出的,结果如下:在var_dump(已定义(PDO::MYSQL_ATTR_LOCAL_infle))上抛出一个错误;//mysql,未定义常量,加载扩展的PDO,true,PDO_-mysql(FALSE!),加载的扩展:核心ctype curl date dom fileinfo filter ftp hash iconv json libxml mbstring mysqlnd openssl pcre PDO PDO_sqlite Phar posix readline反射会话SimpleXML钠SPL sqlite3标准标记器xml xmlreader xmlwriter zlib--我有一些您可能会感兴趣的东西,但这可能与php的local.ini有关。不一定尝试删除docker-compose.yml中创建卷装入到.ini文件的行。确保重建图像以确保容器不读取文件。我看不出你的设置有任何明显的错误,我怀疑你是对的,有什么东西正在覆盖初始配置。您可能必须
rm
该卷才能将其与容器完全分离。
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = test and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
674▕ // If an exception occurs when attempting to run a query, we'll format the error
675▕ // message to include the bindings with SQL, which will make this exception a
676▕ // lot more helpful to the developer instead of just the database's errors.
677▕ catch (Exception $e) {
➜ 678▕ throw new QueryException(
679▕ $query, $this->prepareBindings($bindings), $e
680▕ );
681▕ }
682▕
+33 vendor frames
34 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
upload_max_filesize=40M
post_max_size=40M
# tried adding extension=php_pdo_mysql.so, no luck