Docker PHP 7 的 gd 模块

Docker gd module for PHP 7

我有 docker 文件,它是为 Drupal 8 配置的,但是在我启动 "docker-compose up" 之后,一切都很顺利,但是在安装 Drupal 时它显示 "gd" PHP 的模块未启用。

这是我的 Dockerfile:

FROM php:7-fpm
# Install modules
RUN apt-get update

RUN apt-get install -y software-properties-common

RUN DEBIAN_FRONTEND="noninteractive" add-apt-repository ppa:ondrej/php

RUN apt-get update

RUN apt-get install -y vim curl wget build-essential software-properties-common git ca-certificates

RUN apt-get install -y \
    libbz2-dev \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libpng12-dev \
    libxpm-dev \
    libvpx-dev \
    libmcrypt-dev \
    libmemcached-dev \
    && \

apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \

docker-php-ext-configure gd \
        --with-freetype-dir=/usr/lib/x86_64-linux-gnu/ \
        --with-jpeg-dir=/usr/lib/x86_64-linux-gnu/ \
        --with-xpm-dir=/usr/lib/x86_64-linux-gnu/ \
        --with-vpx-dir=/usr/lib/x86_64-linux-gnu/ \
    && \

docker-php-ext-install \
        bcmath \
        bz2 \
        exif \
        ftp \
        gd \
        gettext \
        mbstring \
        mcrypt \
        mysqli \
        opcache \
        pdo_mysql \
        shmop \
        sockets \
        sysvmsg \
        sysvsem \
        sysvshm \
        zip \
    && \

    pecl install apcu memcached && \
    echo 'extension = apcu.so' > /usr/local/etc/php/conf.d/apcu.ini && \
    echo 'extension = memcached.so' > /usr/local/etc/php/conf.d/memcached.ini

我试试这个方法:Error In PHP5 ..Unable to load dynamic library 但是没用

也许应该试试这个

# Install GD
RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng12-dev
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd

这对你有帮助

FROM php:7.0-fpm
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

使用 PHP 7.2 我在尝试 accepted/other 答案时遇到以下错误:

E: Package 'libpng12-dev' has no installation candidate

这对我有用:

FROM php:7.2-fpm
RUN apt update \
    && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) intl pdo_mysql bcmath mbstring exif gd

注意从 libpng-dev12libpng-dev

的变化