當我嘗試在我正在運行的容器中運行 php artisan migrate 時,出現錯誤,例如找不到我認為未正確安裝 postgres 的驅動程式,我包含了下面的代碼和錯誤幫助我找到了這個。
我的碼頭檔案
FROM php:fpm-alpine
RUN set -ex \
&& apk --no-cache add \
postgresql-dev
RUN docker-php-ext-install pdo pgsql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
COPY . .
RUN composer install
WORKDIR /var/www/html
CMD php artisan serve --host=0.0.0.0 --port=8080
EXPOSE 8080
我的 docker-compose.yml 檔案
version: '3'
services:
php_3:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/var/www/html
ports:
- "8080:8080"
postgres_3:
image: postgres:12.3-alpine
restart: unless-stopped
tty: true
ports:
- "5431:5432"
volumes:
- ./docker/postgres:/var/lib/postgresql/data
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: lara_3
.env 檔案
DB_CONNECTION=pgsql
DB_HOST=postgres_3
DB_PORT=5432
DB_DATABASE=lara_3
DB_USERNAME=root
DB_PASSWORD=root
我的容器正在運行,laravel 也在運行,但是如果我嘗試使用我的 docker 容器遷移表,我會docker-compose exec php_3 sh收到這樣的錯誤。
/var/www/html # php artisan migrate
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:703
699▕ // If an exception occurs when attempting to run a query, we'll format the error
700▕ // message to include the bindings with SQL, which will make this exception a
701▕ // lot more helpful to the developer instead of just the database's errors.
702▕ catch (Exception $e) {
? 703▕ throw new QueryException(
704▕ $query, $this->prepareBindings($bindings), $e
705▕ );
706▕ }
707▕ }
33 vendor frames
34 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
請幫我解決這個問題。
uj5u.com熱心網友回復:
運行命令并安裝 postgres 擴展:
docker-php-ext-install pdo_pgsql pgsql
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/390041.html
標籤:php 拉拉维尔 PostgreSQL的 码头工人 docker-compose
