在Docker中安装GD [英] Installing GD in Docker

查看:362
本文介绍了在Docker中安装GD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker的新手,但是必须维护现有系统.我正在使用的Dockerfile如下:

I am a complete Docker novice but am having to maintain an existing system. The Dockerfile I am using is as below:

FROM php:5.6-apache

RUN docker-php-ext-install mysql mysqli

RUN apt-get update -y && apt-get install -y sendmail

RUN apt-get update && \
    apt-get install -y \
        zlib1g-dev 

RUN docker-php-ext-install mbstring

RUN docker-php-ext-install zip

RUN docker-php-ext-install gd

当我运行'docker build [sitename]'时,一切正常,直到出现错误:

When I run 'docker build [sitename]' everything seems ok until I get the error:

configure: error: png.h not found.
The command '/bin/sh -c docker-php-ext-install gd' returned a non-zero code: 1

此错误的原因是什么?

推荐答案

您应将libpng-dev程序包添加到Dockerfile:

FROM php:5.6-apache

RUN docker-php-ext-install mysql mysqli

RUN apt-get update -y && apt-get install -y sendmail libpng-dev

RUN apt-get update && \
    apt-get install -y \
        zlib1g-dev 

RUN docker-php-ext-install mbstring

RUN docker-php-ext-install zip

RUN docker-php-ext-install gd

然后使用Dockerfile转到目录并运行:

Then go to directory with Dockerfile and run:

docker build -t sitename .

在我的情况下有效:

Removing intermediate container f03522715567
Successfully built 9d69212196a2

如果您有任何错误,请告诉我.

Let me know if you get any errors.

您应该会看到类似这样的内容:

You should see something like this:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
sitename            latest              9d69212196a2        19 minutes ago      414 MB
<none>              <none>              b6c69576a359        25 minutes ago      412.3 MB

只需仔细检查所有内容:

Just to double check everything:

请以这种方式运行docker build命令:

Please run the docker build command this way:

docker build -t sitename:1.0 .

(添加:1.0不应更改任何内容,我添加它只是为了在docker images输出中添加其他行)

(adding :1.0 should not change anything, I added it just to have additional row in docker images output)

然后启动容器:

docker run --name sitename_test -p 80:80 sitename:1.0

它应该可以正常工作.

我假设apache使用的是标准端口(80)-也许您需要对其进行调整.如果您有其他服务/容器在端口80上监听,则可以使您的容器在其他端口上监听:

I assumed that apache is using standard port (80) - maybe you need to adjust that. If you have other services/containers listening on port 80 you can make your container listening on other port:

docker run --name sitename_test -p 8080:80 sitename:1.0

这会将流量从端口8080重定向到容器内部"的端口80.

That will redirect the traffic from port 8080 to port 80 "inside" the container.

通常,您在后台运行容器.为此,将-d选项添加到docker run命令中(但是出于测试目的,您可以省略-d以便在控制台中查看输出).

Normally you run container in the background. To do this add the -d option to the docker run command (but for testing purposes you can omit -d to see output in the console).

如果您决定在后台运行容器,则可以使用docker logs sitename_test检查日志.要跟踪日志(并查看日志中的更新),请使用-f选项:

If you decide to run container in the background you can check logs using docker logs sitename_test. To follow the logs (and see updates in logs) use -f option:

docker logs -f sitename_test

希望有帮助.

这篇关于在Docker中安装GD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆