V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
lestat
V2EX  ›  程序员

求助: PHP 安装 gd 库相关扩展遇到的问题(docker)

  •  
  •   lestat ·
    lestatmiao · 2018-09-18 15:21:24 +08:00 · 4264 次点击
    这是一个创建于 2285 天前的主题,其中的信息可能已经有所发展或是发生改变。

    当前所使用的用于构建镜像的 Dockerfile

    FROM php:7.1-fpm
    
    MAINTAINER Lestat Lee <[email protected]>
    
    #更新 apt-get 源 使用 163 的源,同时备份现有 sources.list
    RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
            echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list && \
            echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list && \
            echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list && \
            echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
    
    
    RUN apt-get update \
        && apt-get install -y \
        git \
        zlib1g-dev \
        libjpeg-dev \
        libpng-dev \
    && curl -sS https://getcomposer.org/installer \
            | php -- --install-dir=/usr/local/bin --filename=composer \
    && composer config -g repo.packagist composer https://packagist.phpcomposer.com \
        && composer global require hirak/prestissimo
    
    
    #安装 gd 库
    RUN docker-php-ext-install -j$(nproc) iconv
        #&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
        #&& docker-php-ext-install -j$(nproc) gd
    
    #安装 redis 扩展
    RUN pecl install redis-4.0.1 \
        && pecl install xdebug-2.6.0 \
        && docker-php-ext-enable redis xdebug
    
    EXPOSE 9000
    

    问题描述

    如果直接在上述 Dockerfile 目录执行docker build .,则会出现和下面一样的错误提示(下面的错误提示是我在没有安装 gd 扩展以及相关依赖的情况下构建镜像后进入到镜像内执行安装命令的提示),php7.1-fpm 默认系统是Debian GNU/Linux 9

    root@78e2aff8c028:/var/www/html# apt-get install -y zlib1g-dev libpng-dev && docker-php-ext-install gd
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Note, selecting 'libpng12-dev' instead of 'libpng-dev'
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:
    
    The following packages have unmet dependencies:
     zlib1g-dev : Depends: zlib1g (= 1:1.2.8.dfsg-2+b1) but 1:1.2.8.dfsg-5 is to be installed
    E: Unable to correct problems, you have held broken packages.
    

    在 google 上也找了很久,都说指定zlib1g的版本后可以解决这个问题,但是我在指定zlib1g版本后依然出现以下的提示

    root@78e2aff8c028:/var/www/html# apt-get install -y zlib1g-dev=1:1.2.8.dfsg-2+b1 libpng-dev && docker-php-ext-install gd
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Note, selecting 'libpng12-dev' instead of 'libpng-dev'
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:
    
    The following packages have unmet dependencies:
     zlib1g-dev : Depends: zlib1g (= 1:1.2.8.dfsg-2+b1) but 1:1.2.8.dfsg-5 is to be installed
    E: Unable to correct problems, you have held broken packages.
    

    我在 php7.0-fpm 镜像的 gd 库安装过程中也遇到同样的问题 除此之外其他扩展安装都很顺利,想请教一下各位这可能是什么原因造成的呢?

    第 1 条附言  ·  2018-09-19 09:44:20 +08:00

    感谢关注,已经解决了,就是镜像源的问题 已更换为科大源

    6 条回复    2018-09-19 21:42:23 +08:00
    realpg
        1
    realpg  
       2018-09-18 21:04:38 +08:00   ❤️ 1
    163 的源…… 你还是换源吧
    realpg
        2
    realpg  
       2018-09-18 21:05:31 +08:00
    哦 抱歉 是 debian 不是 ubuntu 那请忽视我 1 楼回帖……
    liuguang
        3
    liuguang  
       2018-09-18 22:43:16 +08:00   ❤️ 1
    参考 docker 的 PHP 扩展安装说明, 安装 iconv 扩展的那一行可以忽略,其它照抄就可以了
    https://store.docker.com/images/php

    PHP Core Extensions
    For example, if you want to have a PHP-FPM image with iconv and gd extensions, you can inherit the base image that you like, and write your own Dockerfile like this:

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

    还有就是不要用网易的源,因为很多很久没更新了。。。
    科大的源还是不错的,推荐一下: http://mirrors.ustc.edu.cn/help/debian.html
    lestat
        4
    lestat  
    OP
       2018-09-19 09:42:13 +08:00
    @liuguang 用你的方法解决了,果然是镜像的问题...感谢!果断替换掉之前所有 163 的...
    lestat
        5
    lestat  
    OP
       2018-09-19 09:42:28 +08:00
    @realpg 还真是 163 的问题...
    realpg
        6
    realpg  
       2018-09-19 21:42:23 +08:00
    @lestat #5
    哈哈哈哈 ubuntu 的问题是确定的
    debian 的只可能的
    你证实了这种可能
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5289 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 08:53 · PVG 16:53 · LAX 00:53 · JFK 03:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.