88 lines
3.4 KiB
Docker
88 lines
3.4 KiB
Docker
# 基础镜像
|
||
FROM quay.io/wandoubaba517/postgres:{$VERSION}
|
||
|
||
# 切换为root用户执行安装操作
|
||
USER root
|
||
|
||
# 先安装wget(解决wget: not found问题)
|
||
RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*
|
||
|
||
# 配置国内源并采用现代方式管理GPG密钥
|
||
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main non-free contrib" > /etc/apt/sources.list && \
|
||
echo "deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free contrib" >> /etc/apt/sources.list && \
|
||
echo "deb http://mirrors.aliyun.com/debian-security/ bookworm-security main" >> /etc/apt/sources.list && \
|
||
echo "deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main" >> /etc/apt/sources.list && \
|
||
echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib" >> /etc/apt/sources.list && \
|
||
echo "deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib" >> /etc/apt/sources.list && \
|
||
rm -rf /etc/apt/sources.list.d/* && \
|
||
# 添加PostgreSQL国内镜像
|
||
echo "deb http://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/apt/ bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
|
||
# 现代方式:将GPG密钥保存到trusted.gpg.d(替代apt-key add)
|
||
mkdir -p /etc/apt/trusted.gpg.d && \
|
||
wget --no-check-certificate -O /etc/apt/trusted.gpg.d/postgresql.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc && \
|
||
chmod 644 /etc/apt/trusted.gpg.d/postgresql.asc
|
||
|
||
# 安装编译工具和依赖库
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||
build-essential \
|
||
tar \
|
||
gzip \
|
||
postgresql-server-dev-{$VERSION} \
|
||
libprotobuf-c-dev \
|
||
protobuf-c-compiler \
|
||
libgeos-dev \
|
||
libproj-dev \
|
||
libxml2-dev \
|
||
libjson-c-dev \
|
||
gdal-bin \
|
||
libgdal-dev \
|
||
libpcre3-dev \
|
||
libsfcgal-dev \
|
||
libgtk2.0-dev \
|
||
libcunit1-dev \
|
||
xsltproc \
|
||
libtool \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
# 下载并解压PostGIS 3.5.3源码(GitHub官方标签)
|
||
COPY 3.5.3.tar.gz /
|
||
RUN tar -xvzf 3.5.3.tar.gz \
|
||
&& mv postgis-3.5.3 postgis-src
|
||
|
||
# 配置编译选项(基于postgres:和GitHub源码)
|
||
RUN cd postgis-src \
|
||
&& ./autogen.sh \
|
||
&& ./configure \
|
||
--with-pgconfig=/usr/lib/postgresql/{$VERSION}/bin/pg_config \
|
||
--with-geosconfig=/usr/bin/geos-config \
|
||
--with-projdir=/usr \
|
||
--with-gdalconfig=/usr/bin/gdal-config \
|
||
--with-xml2config=/usr/bin/xml2-config \
|
||
--with-jsondir=/usr \
|
||
--with-pcredir=/usr \
|
||
--with-sfcgal=/usr/bin/sfcgal-config \
|
||
--with-raster \
|
||
--with-topology \
|
||
--without-phony-revision
|
||
|
||
# 编译并安装PostGIS 3.5.3
|
||
RUN cd postgis-src \
|
||
&& make -j$(nproc) \
|
||
&& make install \
|
||
&& make comments-install
|
||
|
||
# 创建PostGIS初始化脚本
|
||
RUN echo "CREATE EXTENSION IF NOT EXISTS postgis;" > /docker-entrypoint-initdb.d/init-postgis.sql \
|
||
&& echo "CREATE EXTENSION IF NOT EXISTS postgis_raster;" >> /docker-entrypoint-initdb.d/init-postgis.sql \
|
||
&& echo "CREATE EXTENSION IF NOT EXISTS postgis_topology;" >> /docker-entrypoint-initdb.d/init-postgis.sql \
|
||
&& chmod 644 /docker-entrypoint-initdb.d/init-postgis.sql
|
||
|
||
# 清理编译残留(关键:不卸载tar,避免依赖冲突)
|
||
RUN rm -rf 3.5.3.tar.gz postgis-src \
|
||
&& apt-get purge -y build-essential wget \
|
||
&& apt-get autoremove -y \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
# 切换回postgres用户
|
||
USER postgres
|