【发布时间】:2018-03-27 19:47:55
【问题描述】:
我正在尝试使用 php7.1 docker 创建开发环境。而且无论我出于某种原因尝试什么,它都会显示“驱动程序中发生异常:找不到驱动程序 ”。
我搜索了很多帖子,但没有找到解决我问题的答案。
我正在使用以下 dockerfile 和 docker-compose.yml:
FROM php:7.1-apache
COPY dockerConfig/php.ini /usr/local/etc/php/
RUN apt-get update \
&& apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng12-dev \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd
# Install MCrypt
RUN apt-get update \
&& apt-get install -y libmcrypt-dev \
&& docker-php-ext-install mcrypt
# Install Intl
RUN apt-get update \
&& apt-get install -y libicu-dev \
&& docker-php-ext-install intl
# Install Mysql
RUN docker-php-ext-install pdo pdo_mysql
# Install opcache
RUN docker-php-ext-install opcache
# Configure Apache Document Root
ENV APACHE_DOC_ROOT /var/www/html
# Enable Apache mod_rewrite
RUN a2enmod rewrite
COPY dockerConfig/mysite.local.conf /etc/apache2/sites-available/mysite.local.conf
RUN a2ensite mysite.local.conf
RUN a2dissite 000-default.conf
COPY / /var/www/html
RUN service apache2 restart
version: '3'
services:
mysite-web:
networks:
mysite:
ipv4_address: 178.17.10.3
build:
context: .
dockerfile: Dockerfile
volumes:
- $PWD:/var/www/html
container_name: mysite-dev-running
networks:
mysite:
driver: bridge
ipam:
config:
- subnet: 178.17.10.0/24
构建步骤:
- docker image rm(手动删除所有镜像)
- docker rm xxxxx(手动移除所有容器)
- docker-compose build --no-cache
- docker-compose up -d
导航到网站 symfony 页面,我得到驱动程序未找到。转储php信息,我得到
然后我创建了一个脚本来从执行的“php -m”和 var_dumps 的 url 调用给我的结果
array(42) { [0]=> string(13) "[PHP Modules]" [1]=> string(4) "Core" [2]=> string(5) "ctype" [3]=> string(4) "curl" [4]=> string(4) "date" [5]=> string(3) "dom" [6]=> string(8) "fileinfo" [7]=> string(6) "filter" [8]=> string(3) "ftp" [9]=> string(2) "gd" [10]=> string(4) "hash" [11]=> string(5) "iconv" [12]=> string(4) "intl" [13]=> string(4) "json" [14]=> string(6) "libxml" [15]=> string(8) "mbstring" [16]=> string(6) "mcrypt" [17]=> string(7) "mysqlnd" [18]=> string(7) "openssl" [19]=> string(4) "pcre" [20]=> string(3) "PDO" [21]=> string(9) "pdo_mysql" [22]=> string(10) "pdo_sqlite" [23]=> string(4) "Phar" [24]=> string(5) "posix" [25]=> string(8) "readline" [26]=> string(10) "Reflection" [27]=> string(7) "session" [28]=> string(9) "SimpleXML" [29]=> string(3) "SPL" [30]=> string(7) "sqlite3" [31]=> string(8) "standard" [32]=> string(9) "tokenizer" [33]=> string(3) "xml" [34]=> string(9) "xmlreader" [35]=> string(9) "xmlwriter" [36]=> string(12) "Zend OPcache" [37]=> string(4) "zlib" [38]=> string(0) "" [39]=> string(14) "[Zend Modules]" [40]=> string(12) "Zend OPcache" [41]=> string(0) "" }
所以从 apache 的角度来看,pdo_mysql 似乎是安装的,但不知何故没有启用。
奇怪的是,我有另一个项目使用 symfony 和几乎相同的 docker 配置,而且这个项目可以工作。
有什么想法吗?
谢谢!
更新
事实证明,我包含一个 php.ini 文件的一些遗留代码 apache 正在使用该代码而不是 /usr/local/etc/php 中的正确代码,并且该代码不包含 pdo_mysql 的必要配置。
【问题讨论】:
-
旁白:您可能不需要多次运行
apt-get update。
标签: php symfony docker pdo docker-compose