我是 Docker 的新手,我正在尝试安装 PHP GD扩展。
这是我当前的 Dockerfile:
FROM php:7.4-fpm-alpine
RUN docker-php-ext-install mysqli pdo pdo_mysql bcmath gd
Run Code Online (Sandbox Code Playgroud)
通过运行 docker 时docker-compose build && docker-compose up -d
出现很多错误,最后我收到以下消息:
configure: error: Package requirements (zlib) were not met:
Package 'zlib', required by 'virtual:world', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables ZLIB_CFLAGS
and ZLIB_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
ERROR: Service 'php' failed to build: The command '/bin/sh -c docker-php-ext-install mysqli pdo pdo_mysql bcmath gd' returned a non-zero code: 1
Run Code Online (Sandbox Code Playgroud)
如果末尾没有“gd”,Docker 容器会正常运行。
可能是什么问题,我该如何解决?
Dmi*_*try 17
您可以尝试在 Dockerfile 中添加这些设置:
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
Run Code Online (Sandbox Code Playgroud)
官方文档。希望对你有帮助。
小智 13
在我使用PHP8.0的 docker 中,通过将以下几行添加到我的文件中,我让GD 能够处理 jpg、png 和 webpphp.dockerfile
:
FROM php:8.0-fpm-alpine
# Install dependencies for GD and install GD with support for jpeg, png webp and freetype
# Info about installing GD in PHP https://www.php.net/manual/en/image.installation.php
RUN apk add --no-cache \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
freetype-dev
# As of PHP 7.4 we don't need to add --with-png
RUN docker-php-ext-configure gd --with-jpeg --with-webp --with-freetype
RUN docker-php-ext-install gd
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8245 次 |
最近记录: |