给Docker中的PHP-FPM镜像安装GD扩展

GD是PHP中的一个图像处理扩展,在生成缩略图时需要用到,但使用的php:7.4-fpm-alpine中并未预装,尝试使用docker-php-ext-install gd安装失败,经过查阅资料后终于成功安装上,记录如下。

更换国内镜像源

因为使用的是国内服务器,apline官方源访问很慢,所以更换成阿里云的源。vi /etc/apk/repositories将其中的域名更换成mirrors.aliyun.com,这里以php:7.4-fpm-alpine镜像为例。

1
2
https://mirrors.aliyun.com/alpine/v3.15/main
https://mirrors.aliyun.com/alpine/v3.15/community

安装相关依赖

1
apk add --no-cache --update curl openssl libpng-dev libjpeg-turbo-dev freetype-dev libzip-dev unzip

安装GD扩展

1
docker-php-ext-configure gd --with-freetype --with-jpeg && docker-php-ext-install gd

安装完成后需重启Docker容器,可以查看PHPINFO来验证是否安装成功。

给Docker中的PHP-FPM镜像安装GD扩展

https://goldrun.fyi/posts/3533.html

作者

谨行

发布于

2026-02-04

更新于

2026-02-09

许可协议

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.