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 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿