Docker + PHP7 + GD 导致“调用未定义的函数 imagecreatefromjpeg()”的问题
我在尝试使用此功能生成容器创建映像时遇到问题: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
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/