嘗試在 docker 中執行“php artisan migrate”返回以下錯誤
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