在lumen 5.6应用中找不到驱动器错误(在docker + alpine linux + nginx + php-fpm 7.2中运行)

时间:2018-11-28 18:49:16

标签: php docker migration lumen

我试图将数据库访问权限添加到我的Lumen 5.6应用程序中,该应用程序当前在以下LEMP堆栈中的docker中运行:

  • 高山Linux
  • PHP-FPM 7.2.x
  • NGINX

我的撰写文件如下:

version: '2.1'

services:

  webhooks-mysql:
    container_name: webhooks-mysql
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 123456
      MYSQL_DATABASE: webhooks
      MYSQL_USER: webhooks
      MYSQL_PASSWORD: 123456
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
      timeout: 20s
      retries: 10
    ports:
    - "33401:3306"

  webhooks-service:
    container_name: webhooks-service
    depends_on:
      webhooks-mysql:
        condition: service_healthy
    build: .
    mem_limit: 64M
    ports:
      - "9050:80"
    volumes:
      - ./:/app:cached

并且我的.env中包含以下内容:

APP_NAME=webhooks
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:123456=
APP_TIMEZONE=UTC

DB_CONNECTION=mysql
DB_HOST=webhooks-mysql
DB_DATABASE=webhooks
DB_USERNAME=webhooks
DB_PASSWORD=123456

最后;我的容器具有所有require依赖项:

php7 php7-fpm php7-mysqli php7-pdo php7-openssl php7-mbstring
php7-xml php7-tokenizer php7-json php7-openssl php7-curl php7-zlib 
php7-xml php7-phar php7-intl php7-dom php7-xmlreader php7-ctype 
php7-mbstring php7-gd php7-zip git nginx supervisor curl zip unzip

和以下作曲家软件包:

  "require": {
    "php": ">=7.1.3",
    "laravel/lumen-framework": "5.6.*",
    "vlucas/phpdotenv": "~2.2",
    "wikimedia/ip-set": "^1.2",
    "doctrine/dbal": "^2.8"
  }

当我尝试在容器中运行迁移时,出现以下错误:

  

/ app#php artisan migration

     

在Connection.php第664行中:                                                                                                                              找不到驱动程序(SQL:从information_schema.tables中选择*   其中table_schema = webhooks,table_name =)

     

在PDOConnection.php第50行中:                               找不到驱动程序

我为什么会收到此错误的任何想法?

我已经验证了php-mysql / pdo扩展已加载,env值正确等...我似乎无法弄清楚。

2 个答案:

答案 0 :(得分:0)

由于docker镜像已被完全剥离,因此您可能会遇到更多依赖关系,我遇到了相同的问题,并通过添加扩展名pdo_mysql来解决它,除了已经拥有的扩展名({{1 },pdomysqli)。

答案 1 :(得分:0)

我通过使用以下 Dockerfile 解决了该问题:

FROM php:7.2-fpm-alpine

# Install packages
RUN docker-php-ext-configure pdo_mysql && docker-php-ext-install pdo_mysql \
 && apk add --update \
    ca-certificates \
    curl \
    git \
    zip \
    unzip \
    nano \
 && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \
 && rm -rf /var/cache/apk/*

# Configure php-fpm
COPY scripts/fpm-pool.conf /etc/php7/php-fpm.d/zzz_custom.conf
COPY scripts/php.ini /usr/local/etc/php/conf.d/zzz_custom.ini

# Add Application
WORKDIR /app
ADD . /app