ds261634878 2017-02-10 16:10
浏览 92
已采纳

libgd没有安装在php:5.6-cli docker中

I have a project inside a container and Im trying to use the gd lib for image create.

I do inside the bash of the container this command:

apt-get install php5-gd

Nothing changes after restart and execute php -m

What should I do?

Edit:

I added to my Dockerfile:

RUN apt-get -qq update && apt-get -qq install libpng-dev
RUN docker-php-ext-install gd

I execute docker build -t [name]

But when I execute the bash and type : php -m

[PHP Modules]
Core
ctype
curl
date
dom
ereg
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysql
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
  • 写回答

1条回答 默认 最新

  • dorpbn1027 2017-02-10 16:22
    关注

    Don't install gd manually. There's the docker-php-ext-install for that.

    Inside the dockerfile, add:

    RUN docker-php-ext-install gd
    

    There is a bit of an annoyance with docker-php-ext-install that you have to figure out manually what dependencies you'll need. They don't resolve automatically. Due to this, the command will crash on its own, with:

    configure: error: png.h not found.
    

    If you look for the error, you will realize that you need libpng-dev.

    Hence finally, the whole Dockerfile should look something like this:

    FROM php:5.6-cli
    RUN apt-get -qq update && apt-get -qq install libpng-dev
    RUN docker-php-ext-install gd > /dev/null
    

    docker-php-ext-install is a bit verbose in its output, hence I like to pipe its output to /dev/null. Errors and warnings will still be printed.

    You can check that the image has the proper extension by running the image:

    docker build -t php-gd .
    docker run php-gd /bin/bash -c "php -m | grep gd"
    

    Will print:

    gd
    

    Same within a docker-compose stack:

    docker-compose.yml:

    gd-example:
        build: .
        tty: true
    
    docker-compose up --build -d
    docker ps // to find container's name. You may also set in the config
    docker exec -it docker_gd-example_1 php -m | grep gd      
    

    Two sidenotes:

    1. From your question is was not clear if you built your container and then run apt-get install php5-gd from it. If so, then that would only instal php5-gd within that container and everytime you recreate it, it will be gone. Always add stuff to a container from within the Dockerfile.

    2. Give php:7.1-cli a try. Do you really need to support php 5.6? ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?