因为环境依赖问题,直接安装gd库会报错,所以需要先安装更新依赖
先更新软件源,比如换成中科大的
```
echo 'deb https://mirrors.ustc.edu.cn/debian/ buster main contrib non-free' > /etc/apt/sources.list
echo 'deb https://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free' >> /etc/apt/sources.list
echo 'deb https://mirrors.ustc.edu.cn/debian/ buster-backports main contrib non-free' >> /etc/apt/sources.list
echo 'deb https://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free' >> /etc/apt/sources.list
echo 'deb-src https://mirrors.ustc.edu.cn/debian/ buster main contrib non-free' >> /etc/apt/sources.list
echo 'deb-src https://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free' >> /etc/apt/sources.list
echo 'deb-src https://mirrors.ustc.edu.cn/debian/ buster-backports main contrib non-free' >> /etc/apt/sources.list
echo 'deb-src https://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free' >> /etc/apt/sources.list
```
然后更新,安装
```
apt update
apt install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev
```
这时还会遇到环境依赖问题,报错如下
```
zlib1g-dev : Depends: zlib1g (= 1:1.2.11.dfsg-1+deb10u1) but 1:1.2.11.dfsg-2+deb11u1 is to be installed
```
此时要降级安装所需依赖
~~~
apt install zlib1g=1:1.2.11.dfsg-2ubuntu1
~~~
安装好后,就可以安装gd库了,不过需要加入相应的编译参数编译,命令如下(php7.4)
```
docker-php-ext-configure gd --with-webp=/usr/include/webp --with-jpeg=/usr/include --with-freetype=/usr/include/freetype2/
```
或者(php7.4之前)
```
docker-php-ext-configure gd --with-webp-dir=/usr/include/webp --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-freetype-dir=/usr/include/freetype2
```
然后是安装了
```
docker-php-ext-install gd
```
接下来,重新运行容器,就好了