尝试在 docker 中运行“php artisan migration”返回以下错误
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = admin 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 php-i`
34 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
找到了我需要启用 pdo_mysql 的解决方案,(我认为)我在 Dockerfile 中已经启用了
FROM php:7.3
RUN apt-get update -y && apt-get install -y openssl zip unzip git
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo mbstring pdo_mysql
WORKDIR /app
COPY . .
RUN composer install
CMD php artisan serve --host=0.0.0.0
EXPOSE 8000
此外,当我尝试查找 php.ini 文件并简单地取消注释 pdo_mysql 扩展时,php-i
显示没有 php.ini 文件
Loaded Configuration File => (none)
答案1
看来你没有在docker环境中安装php-MySQL扩展
RUN apt-get update \
&& apt-get -y --no-install-recommends install php7.3-mysql php7.3-intl mysql-client php-common openssl zip unzip git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo mbstring pdo_mysql
WORKDIR /app
COPY . .
RUN composer install
CMD php artisan serve --host=0.0.0.0
EXPOSE 8000