php - Docker mysql 找不到驱动程序
问题描述
我试图在容器中运行 laravel 应用程序,但在迁移时找不到驱动程序。拉拉维尔 8、mysql 8、php 8
码头工人撰写
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
.env
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=test
# I have also tried creating another user and granting all privileges to it, same thing
它的一些缺少的扩展我无法弄清楚它是什么,也许我正在安装与 php 8 不兼容的 pdo?用户和数据库已正确创建。
错误
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))
注意:我在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
解决方案
推荐阅读
- javers - 在 Javers 中构建 ObjectGraph
- laravel - 在 Laravel 中使用计数连接表多列 groupBy
- npm - 使用自定义命令(构建)的 Devops npm 任务不起作用
- spring-boot - 我想在 Spring Boot 应用程序中禁用自动删除 JMS 队列
- heroku - 如何在 Heroku 服务器上运行 mocha 脚本?
- python - 如何在模板错误时跳过 Flask 缓存
- python - Python打印同一行
- javascript - 使用 python selenium 单击部分 div 链接
- python - 评估时间序列的频率、持续时间和值
- plugins - 鹡鸰的 Draftail 提及插件