我一直在尝试将一些PHP扩展安装到定制的docker映像中(基于官方的php:7.1.21-fpm-alpine3.8映像),但没有成功。我真的不知道我做错了什么,因为我过去能够做同样的事情。
当我运行docker-composup时,似乎映像(php-fpm,nginx和mysql)已正确构建,并且正在运行3个docker容器。
但是,当我检查我的phpinfo文件时,我可以看到扩展名没有加载。(pdo_mysql,zip,IMAP和xDebug)
当我进入php-fpm容器并检查/usr/local/etc/php/conf.d目录时,我可以看到所有这些扩展名的ini文件:
- docker-php-ext-imap.ini
- docker-php-ext-pdo_mysql.ini
- docker-php-ext-xdebug.ini
- docker-php-ext-zip.ini
- 我的公司.ini
phpinfo 还通知我"扫描此目录以查找其他.ini文件"为空(无值)
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 日志,因为正文限制为 30 000 个字符
编辑: 更奇怪的是,我在我的 docker-compose 文件中创建了一个额外的服务,其中包含一个看起来或多或少相同的 dockerfile。当我检查该新服务的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 文件中的值包含双引号。删除引号解决了这个问题。