【发布时间】:2018-04-27 18:45:35
【问题描述】:
我在尝试使用 imagecreatefromjpeg 创建映像时遇到问题,使用此 Dockerfile 来生成容器:
FROM php:7.1-apache
RUN apt-get update && \
apt-get install -y -qq git \
libjpeg62-turbo-dev \
apt-transport-https \
libfreetype6-dev \
libmcrypt-dev \
libpng12-dev \
libssl-dev \
zip unzip \
nodejs \
npm \
wget \
vim
RUN pecl install redis && docker-php-ext-enable redis
RUN docker-php-ext-install -j$(nproc) iconv mcrypt zip pdo pdo_mysql gd bcmath
COPY ./containers/yii.conf /etc/apache2/sites-available/000-default.conf
RUN for mod in rewrite headers; do a2enmod $mod; done && service apache2 restart
WORKDIR /var/www/html/
GD 已正确安装(libjpeg 也已安装 - 都出现在 php -i 和 phpinfo() 中)但 imagecreatefromjpeg 不起作用,我不知道为什么。
我还运行 apt install libjpeg-dev libpng-dev libfreetype6-dev 尝试 ~force~ 重新安装(或重新配置),但似乎没有成功(是的,我也重新启动了容器)。
root@e8db647c96c4:/var/www/html# php -i | grep -i GD
/usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
gd
GD Support => enabled
GD Version => bundled (2.1.0 compatible)
gd.jpeg_ignore_warning => 1 => 1
root@e8db647c96c4:/var/www/html#
root@e8db647c96c4:/var/www/html# docker-php-ext-enable gd
warning: gd (gd.so) is already loaded!
root@e8db647c96c4:/var/www/html#
我试过apt install libgd2-xpm-dev*,但显然不能解决问题。
已解决
我错过了
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd
进入我的 Dockerfile。
完整修改的 Dockerfile:
FROM php:7.1-apache
RUN apt-get update && \
apt-get install -y -qq git \
libjpeg62-turbo-dev \
apt-transport-https \
libfreetype6-dev \
libmcrypt-dev \
libpng12-dev \
libssl-dev \
zip unzip \
nodejs \
npm \
wget \
vim
RUN pecl install redis && docker-php-ext-enable redis
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) iconv mcrypt zip pdo pdo_mysql gd bcmath
COPY ./containers/yii.conf /etc/apache2/sites-available/000-default.conf
RUN for mod in rewrite headers; do a2enmod $mod; done && service apache2 restart
WORKDIR /var/www/html/
【问题讨论】:
-
docker-php-ext-configure gd命令是我出售类似错误所需要的。谢谢! -
请将您的解决方案移至自己的答案,谢谢。
-
PHP 7.4 的新版本不再有
--with-freetype-dir和--with-jpeg-dir选项。相反,我使用了--with-freetype和--with-jpeg选项,我的测试套件又变成了绿色。