PHP 未安装/加载/启用扩展,使用官方 PHP docker 图像

PHP extensions not installed / loaded / enabled, using the official PHP docker image

我整天都在尝试将一些 PHP 扩展安装到自定义 docker 图像中(基于官方 php:7.1.21-fpm-alpine3.8图像),但没有成功。我真的不知道我做错了什么,因为我过去也能做同样的事情。

当我 运行 docker-compose up 时,图像(php-fpm、nginx 和 mysql)似乎构建正确并且 3 docker 容器正在 运行ning。

但是,当我检查 phpinfo 文件时,我发现没有加载扩展。 (pdo_mysql、zip、imap 和 xdebug)

当我进入 php-fpm 容器并检查 /usr/local/etc/php/conf.d 目录时,我可以看到所有这些扩展的 ini 文件:

php信息还告诉我 "Scan this dir for additional .ini files" 为空(无值)

app.dockerfile:

FROM php:7.1.21-fpm-alpine3.8

# Clean & update package manager
RUN rm -rf /var/cache/apk/* && \
    rm -rf /tmp/*

RUN apk update

# Install tools
RUN apk add --no-cache ${PHPIZE_DEPS} \
    imap-dev \
    openssl-dev \
    zlib-dev

# Install PHP extensions
RUN docker-php-ext-install pdo pdo_mysql zip

RUN docker-php-ext-configure imap --with-imap --with-imap-ssl \
    && docker-php-ext-install imap

RUN pecl install xdebug \
    && docker-php-ext-enable xdebug

# Copy configuration file(s)
COPY php-ini/my-firm.ini /usr/local/etc/php/conf.d/my-firm.ini

# Set workdir
WORKDIR /var/www

docker-compose.yml 文件:

version: '3'

services:
  api-lumen-app:
    build:
      context: ./api-lumen
      dockerfile: app.dockerfile
    # name our image
    image: my-firm/api-lumen-app-development
    # set working dir
    working_dir: /var/www
    # bound volume for easy file sharing between host & docker container
    volumes:
      - ../api-lumen/:/var/www
    env_file:
      - .env
    links:
      - api-database
    # can be used as DNS name to access another (external) service
    container_name: api-lumen.app.my-firm.local
    # environment variables
    environment:
      # Application
      APP_ENV: ${APP_ENV}
      APP_KEY: ${APP_KEY_LUMEN}
      APP_DEBUG: ${APP_DEBUG}
      APP_URL: ${APP_URL_LUMEN}
      # Database
      DB_HOST: ${DB_HOST}
      DB_DATABASE: ${DB_DATABASE}
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}
      # Caching
      CACHE_DRIVER: ${CACHE_DRIVER}
      # Queue
      QUEUE_DRIVER: ${QUEUE_DRIVER}
      # Mail general
      MAIL_DRIVER: ${MAIL_DRIVER}
      MAIL_ENCRYPTION: ""
      MAIL_FROM_ADDRESS: ""
      MAIL_FROM_NAME: ""
      MAIL_HOST: ""
      MAIL_PORT: ""
      MAIL_USERNAME: ""
      MAIL_PASSWORD: ""
      # Imap
      IMAP_USERNAME: ${IMAP_USERNAME}
      IMAP_PASSWORD: ${IMAP_PASSWORD}
      IMAP_HOST: ${IMAP_HOST}
      IMAP_PORT: ${IMAP_PORT}
      IMAP_ENABLE_SSL: ${IMAP_ENABLE_SSL}
      IMAP_VALIDATE_CERTIFICATE: ${IMAP_VALIDATE_CERTIFICATE}
      IMAP_FOLDER: ${IMAP_FOLDER}
      # Mail generator
      MAILGENERATOR_BASE_URI: ${MAILGENERATOR_BASE_URI}
      # Exact
      EXACT_BASE_URI: ${EXACT_BASE_URI}
      EXACT_DIVISION: ${EXACT_DIVISION}
      EXACT_CLIENT_ID: ${EXACT_CLIENT_ID}
      EXACT_CLIENT_SECRET: ${EXACT_CLIENT_SECRET}
      # Google
      GOOGLE_MAPS_BASE_URI: ${GOOGLE_MAPS_BASE_URI}
      GOOGLE_MAPS_API_KEY: ${GOOGLE_MAPS_API_KEY}
      GOOGLE_MAIL_BASE_URI: ${GOOGLE_MAIL_BASE_URI}
      GOOGLE_MAIL_APPLICATION_NAME: ${GOOGLE_MAIL_APPLICATION_NAME}
      GOOGLE_MAIL_AUTH_CONFIG: ${GOOGLE_MAIL_AUTH_CONFIG}
      GOOGLE_MAIL_ACCESS_TYPE: ${GOOGLE_MAIL_ACCESS_TYPE}
      GOOGLE_MAIL_PROMPT: ${GOOGLE_MAIL_PROMPT}

  # The API (Lumen) Web Server
  api-lumen-web:
    build:
      context: ./api-lumen
      dockerfile: web.dockerfile
    # name our image
    image: my-firm/api-lumen-web-development
    # set working dir
    working_dir: /var/www
    # bound volume for easy file sharing between host & docker container
    volumes:
      - ../api-lumen/:/var/www
    ports:
      - 8003:80
    links:
      - api-lumen-app
    # can be used as DNS name to access another (external) service
    container_name: api-lumen.web.my-firm.local

  # The API Database
  api-database:
    # official (public) image
    image: mysql:5.6.41
    # named volume for persistent storage
    volumes:
      - dbdata:/var/lib/mysql
    env_file:
      - .env
    ports:
      - 3306:3306
    # can be used as DNS name to access another (external) service
    container_name: api.database.my-firm.local
    # environment variables
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}

# named volumes
volumes:
  dbdata:

关于 docker-compose 日志,请参阅我在这个问题中的下一个 post,因为正文限制为 30 000 个字符

编辑: 更奇怪的是,我在我的 docker-compose 文件中创建了一个附加服务,其中的 docker 文件看起来或多或少相同。当我检查该新服务的 phpinfo 文件时,它确实加载了 pdo_mysql?!

app.dockerfile(新服务):

FROM php:7.1.21-fpm-alpine3.8

# Clean & update package manager
RUN rm -rf /var/cache/apk/* && \
    rm -rf /tmp/*

RUN apk update

# Install tools
RUN apk add --no-cache ${PHPIZE_DEPS}

# Install PHP extensions
RUN docker-php-ext-install pdo pdo_mysql

RUN pecl install xdebug \
    && docker-php-ext-enable xdebug

# Copy configuration file(s)
COPY php-ini/my-firm.ini /usr/local/etc/php/conf.d/my-firm.ini

# Set workdir
WORKDIR /var/www

我发现了问题:我正在我的 docker-compose.yml 文件中加载一个 .env 文件,并且该 .env 文件中的值包含 double-quotes。删除引号解决了问题。