我整天都在尝试将一些PHP扩展安装到定制的docker映像中(基于官方php:7.1.21-fpm-alpine3.8映像),但是没有成功。我真的不知道自己在做什么错,因为我过去能够做同样的事情。
当我运行docker-compose up时,似乎图像(php-fpm,nginx和mysql)已正确构建,并且3个docker容器正在运行。
但是,当我检查phpinfo文件时,可以看到未加载扩展名。 (pdo_mysql,zip,imap和xdebug)
当我进入php-fpm容器并检查/usr/local/etc/php/conf.d目录时,我可以看到所有这些扩展的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:
有关主体组成限制为30000个字符,请参阅我在本问题中的下一篇帖子中的docker-compose日志
编辑: 令我更加陌生的是,我在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
答案 0 :(得分:1)
我发现了问题:我正在将docker.compose.yml文件中的.env文件加载到该.env文件中的值包含双引号。删除引号即可解决此问题。