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
这个错误的原因是什么?
What is the cause of this error?
推荐答案
您应该将 libpng-dev 包添加到您的 Dockerfile:
You should add the libpng-dev package to your 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
- 点赞
- 收藏
- 关注作者
评论(0)