专属域名
文档搜索
轩辕助手
Run助手
邀请有礼
返回顶部
快速返回页面顶部
收起
收起工具栏
轩辕镜像 官方专业版
轩辕镜像 官方专业版轩辕镜像 官方专业版官方专业版
首页个人中心搜索镜像

交易
充值流量我的订单
工具
提交工单镜像收录一键安装
Npm 源Pip 源Homebrew 源
帮助
常见问题
其他
关于我们网站地图

官方QQ群: 1072982923

cheewai/postgis Docker 镜像 - 轩辕镜像 | Docker 镜像高效稳定拉取服务

热门搜索:openclaw🔥nginx🔥redis🔥mysqlopenjdkcursorweb2apimemgraphzabbixetcdubuntucorednsjdk
postgis
cheewai/postgis
自动构建
cheewai
PostgreSQL and PostGIS in a Docker container
2 次收藏下载次数: 0状态:自动构建维护者:cheewai仓库类型:镜像最近更新:5 年前
轩辕镜像,不浪费每一次拉取。点击查看
镜像简介版本下载
轩辕镜像,不浪费每一次拉取。点击查看

PostgreSQL and PostGIS in a Docker container

2020-05-27 update

Due to work commitment, I may not catch up with latest versions timeously. So I recommend you do this:

  • Switch to use the versatile official postgis/postgis image which offers many tagged combination of PostgreSQL and PostGIS versions
  • If you need the POSTGRES_UID feature, grab my set-postgre***d.sh and use it as your docker-entrypoint

This project creates a PostgreSQL and PostGIS database server in a Docker container. It is inspired by base image mdillon/postgis and includes rsyslog.

The tiny postgres:alpine is not used as the base image because it is tricky to compile PostGIS in it.

With rsyslog, one could log to files and feed into feature-rich log analysis software like Graylog2, ELK stack, etc. in real time in postgresql.conf:

log_destination = 'stderr,syslog'
logging_collector = on
log_directory = '/var/log/postgresql'
log_filename = 'postgresql-%Y%m%d-%H%M%S.log'
log_rotation_size = 1GB
log_rotation_age = 1d
log_min_duration_statement = 250ms
log_checkpoints = on
log_connections = on
log_disconnections = on
log_lock_waits = on
log_statement = 'ddl'
log_temp_files = 0
log_autovacuum_min_duration = 1000

CAVEAT

  • Beware of general ation when running database server, []
    • Specify volume explicitly to persist data
    • Do not use dm-thin/lvmthin backed storage driver for Docker
    • Don't use persisted data directory with a different image
    • Customize pg_hba.conf
  • When upgrading from an existing database with an older release of PostGIS, be sure to read the upgrade instructions on [***] in case the instructions below are outdated.
ALTER EXTENSION postgis UPDATE;
ALTER EXTENSION postgis_topology UPDATE;

# or to specific version
ALTER EXTENSION postgis UPDATE TO "2.5.1";
ALTER EXTENSION postgis_topology UPDATE TO "2.5.1";
ALTER EXTENSION postgis_tiger_geocoder UPDATE TO "2.5.1";

Docker entrypoint and custom initialization

The base image Dockerfile uses /docker-entrypoint.sh as ENTRYPOINT

From the base image README:

If you would like to do additional initialization in an image derived from this one, add one or more *.sql or *.sh scripts under /docker-entrypoint-initdb.d (creating the directory if necessary). After the entrypoint calls initdb to create the default postgres user and database, it will run any *.sql files and source any *.sh scripts found in that directory to do further initialization before starting the service.

These initialization files will be executed in sorted name order as defined by the current locale, which defaults to en_US.utf8. Any *.sql files will be executed by POSTGRES_USER, which defaults to the postgres superuser. It is recommended that any psql commands that are run inside of a *.sh script be executed as POSTGRES_USER by using the --username "$POSTGRES_USER" flag. This user will be able to connect without a password due to the presence of trust authentication for Unix socket connections made inside the container.

...

If there is no database when postgres starts in a container, then postgres will create the default database for you. While this is the expected behavior of postgres, this means that it will not accept incoming connections during that time. This may cause issues when using automation tools, such as docker-compose, that start several containers simultaneously.

Usage

Before you use the sample file below, read about:

  • Mountpoint (docker volume) and PGDATA [***]

  • Full list of environment variables [***]_/postgres/ for other possibilities

Create your docker-compose.yml file
version: '2.2'
services:
  db:
    image: cheewai/postgis
    environment:
      - PGDATA=/var/lib/postgresql/data
    ports:
     - "5432:5432"
    volumes:
     # Mount your data directory so your database may be persisted
     - path/to/data/directory:/var/lib/postgresql/data
     #*** If you have no existing database, comment the following the first-run
     #*** Empty data directory triggers initdb to be run
     # Customize access control to overwrite the default
     #- path/to/pg_hba.conf:/var/lib/postgresql/data/pg_hba.conf:ro
     # Customize server tuning parameters to overwrite the default
     #- path/to/postgresql.conf:/var/lib/postgresql/data/postgresql.conf:ro
    restart: on-failure:5
Initialize PostgreSQL database

When the container starts up, if PGDATA directory is empty, the bootstrapping script will run docker-entrypoint.sh to initialize PostgreSQL database.

The initialization script will also execute any additional bootstrapping scripts it finds in /docker-entrypoint-initdb.d/ if this directory exists. Subsequent runs of the container will ignore /docker-entrypoint-initdb.d/.

Check out the base image documentation for details.

docker-compose -f docker-compose.yml up

When you see the database server ready message, you may stop the container and customise postgres.conf and pg_hba.conf in PGDATA directory.

Optional. Set UID and GID of postgres user

By default, the postgres user in the Docker image is assigned some arbitrary numeric UID/GID i.e. 999, during package installation. By specifying the following environment variables to the same UID and GID of the user who runs docker-compose, the database files created will be owned the same user. Add these lines with the appropriate indentation to your docker-compose.yml:

environment:
  - POSTGRES_UID={your_uid}
  - POSTGRES_GID={your_gid}
entrypoint: ["/set-postgre***d.sh"]

Known Issues/Errors

Refer to [***]

Production Use

  • The default postgresql.conf is good enough for development but for production use, *** using guided parameter tuning. Or run pgtune in a docker.

  • Plan for disaster.

Seriously *** Barman first. Maybe it is adequate and superior to the other suggestions below

Daily Backup

This repo includes a script, dumpdb.sh which is intended to be run by Postgresql admin user postgres inside the container. When executed, it dumps the roles, schema (including GRANT) and all databases as separate files suffixed with yyyy-mm-dd

You can schedule a nightly cron job to execute it using docker exec, e.g.

# Obviously /restore must be persisted outside the container
docker exec {DOCKER_NAME} su - postgres /runtime/dumpdb.sh /restore

You should *** storing the daily dumps to a different server.

To restore a specific database. This will wipe out all existing data:

docker exec -it {DOCKER_NAME} su - postgres
pg_restore -j4 --clean --create {dumpfile}

To restore every database, either drop all your databases first, or run a separate instance of postgresql container but pointing to an existing empty PGDATA_DIR directory.

pg_restore -j4 -d postgres {postgres_dumpfile}
psql -f {roles_sql}
grep GRANT {schema_sql} | psql
# Repeat for every dumpfile
pg_restore -j4 --clean --create {dumpfile}
Continuous Archiving

First and foremost, read the official documentation for Continuous Archiving and Point-in-Time Recovery for your specific version of Postgresql.

At all times, PostgreSQL maintains a write ahead log (WAL) in the pg_xlog/ subdirectory of the cluster's data directory. The log records every change made to the database's data files. This log exists primarily for crash-safety purposes: if the system crashes, the database can be restored to consistency by "replaying" the log entries made since the last checkpoint.

Make use of these settings in postgresql.conf to enable WAL archiving:

  • wal_level = hot_standby
  • archive_mode = on
  • archive_command = 'rsync -a %p postgres@replica-host:/path/to/wal_archive/%f'

To delete old WAL archive using pg_archivecleanup, read [***]

High-availability

postgresql.conf has a section for replication. Refer to [***]

Upgrade database between major releases

Between upgrade between minor releases PostgreSQL, restarting the server using the new binaries should just work. For PostGIS, you can usually perform soft upgrade while the database is online.

It turns out that there several online approaches available but your mileage may vary:

  • PGLogical
  • Slony-I
  • Skytool3 + PGQ + londiste3

This section refers specifically the most conservative approach to upgrade between major releases of either PostgreSQL or PostGIS. The bundled pg_upgrade is only good for vanilla PostgreSQL databases that do not use PostGIS extension. I haven't found a reliable way other than hard upgrade which requires the server to be offline during the upgrade. An outline of the steps involved:

  • Dump roles, pg_dumpall --roles-only -U postgres -f roles.sql

  • Dump individual database, `pg_dump -Fc -b -U postgres {db} -f {db}.dmp

  • Start up an instance of the desired new version of PostgreSQL server

    • make sure initdb is executed
    • avail roles.sql and all the dump files in a mounted volume
  • Create roles, psql -U postgres -f roles.sql

  • If your dump file is huge, *** changing your postgresql.conf temporarily to speed up the restore process, [***]

  • Create database and import from dump file. This script serves only as an example to be adapted according to your needs, particularly the path to postgis_restore.pl, the database encoding, locale, and PostGIS extensions.

#! /bin/bash
#
# - To be run as 'postgres' user inside container
# - /restore contains all the database dump files
# - /restore must be writable by 'postgres'

# where 'pg_dump -Fc -b -v' output is, named as {dbname}-*.dmp
DMPDIR="${DMPDIR:-/restore}"

cd $DMPDIR || {
  echo "DMPDIR '$DMPDIR' must point to existing directory where {dbname}-*.dmp is found" >&2
  exit 1
}

if [ $# -gt 0 ]; then
  _flist="$@"
  for _f in $_flist; do
    [ -f $_f ] || {
      echo "pg_dump file '$DMPDIR/$_f' not found" >&2
      exit 1
    }
  done
else
  _flist="$(echo *.dmp)"
fi

for _f in $_flist ; do
  _db="${_f%-*}"
  _dbuniq=$(echo $_db* | wc -l)
  [ $_dbuniq -eq 1 ] || {
    echo "More than one dmp file for '$_db' in $DMPDIR" >&2
    exit
  }
  createdb -E UTF8 --locale=en_ZA.UTF-8 $_db 
  _err=$?
  [ $_err -eq 0 ] || continue
  psql $_db -c "CREATE EXTENSION postgis;" 
  psql $_db -c "CREATE EXTENSION postgis_topology;"
  time /usr/share/postgresql/9.6/contrib/postgis-2.3/postgis_restore.pl $_f | psql $_db >"${DMPDIR}/restore-${_db}.log" 2>&1
done
查看更多 postgis 相关镜像 →
postgis/postgis logo
postgis/postgis
postgis
PostGIS是PostgreSQL对象关系型数据库的空间数据库扩展器,它为PostgreSQL增添了对空间数据类型(如点、线、面、几何体集合等)的支持,提供空间索引功能以提升空间数据查询效率,并集成了丰富的空间分析函数(包括距离计算、缓冲区分析、叠加操作等),使PostgreSQL能够高效存储、管理与分析空间数据,广泛应用于地理信息系统(GIS)、位置服务、地图绘制等领域。
292 次收藏1亿+ 次下载
18 天前更新
postgis/postgis-build-env logo
postgis/postgis-build-env
postgis
这是用于PostGIS持续集成测试的环境,集成了其核心依赖组件PostgreSQL、GDAL、PROJ及GEOS的多种版本,旨在通过覆盖不同版本组合,确保PostGIS在各类环境配置下的兼容性与稳定性,为开发过程中的自动化测试提供可靠支撑。
9 次收藏10万+ 次下载
18 天前更新
corpusops/postgis logo
corpusops/postgis
corpusops
CorpusOps Docker Images是一个预构建且可定制的Docker镜像集合,针对各类开发与生产环境优化,包含用于CI/CD流水线、基础设施自动化及应用部署的工具,专注于安全性、性能与易维护性,并提供全面文档及社区驱动的更新。
5 次收藏10万+ 次下载
1 年前更新
rootpublic/postgis logo
rootpublic/postgis
rootpublic
暂无描述
4.2千+ 次下载
6 个月前更新
mdillon/postgis logo
mdillon/postgis
mdillon
PostGIS container based on the official Postgres container.
425 次收藏5000万+ 次下载
6 年前更新
kartoza/postgis logo
kartoza/postgis
kartoza
即开即用的PostGIS地理空间数据库是基于PostgreSQL的高效空间扩展解决方案,可快速存储、查询和分析各类地理空间数据,涵盖矢量数据(如点、线、面要素)与栅格数据处理,支持空间索引优化、地理编码转换、拓扑关系验证及空间分析函数等核心功能,适用于GIS应用开发、城市规划、环境监测、位置服务等多场景,无需复杂配置即可直接部署使用。
198 次收藏1000万+ 次下载
3 个月前更新

轩辕镜像配置手册

探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式

Docker 配置

登录仓库拉取

通过 Docker 登录认证访问私有仓库

专属域名拉取

无需登录使用专属域名

K8s Containerd

Kubernetes 集群配置 Containerd

K3s

K3s 轻量级 Kubernetes 镜像加速

Dev Containers

VS Code Dev Containers 配置

Podman

Podman 容器引擎配置

Singularity/Apptainer

HPC 科学计算容器配置

其他仓库配置

ghcr、Quay、nvcr 等镜像仓库

系统配置

Linux

在 Linux 系统配置镜像服务

Windows/Mac

在 Docker Desktop 配置镜像

MacOS OrbStack

MacOS OrbStack 容器配置

Docker Compose

Docker Compose 项目配置

NAS 设备

群晖

Synology 群晖 NAS 配置

飞牛

飞牛 fnOS 系统配置镜像

绿联

绿联 NAS 系统配置镜像

威联通

QNAP 威联通 NAS 配置

极空间

极空间 NAS 系统配置服务

网络设备

爱快路由

爱快 iKuai 路由系统配置

宝塔面板

在宝塔面板一键配置镜像

需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单

镜像拉取常见问题

使用与功能问题

docker search 报错:专属域名下仅支持 Docker Hub 查询

docker search 报错问题

网页搜不到镜像:Docker Hub 有但轩辕镜像搜索无结果

镜像搜索不到

离线传输镜像:无法直连时用 docker save/load 迁移

离线传输镜像

Docker 插件安装错误:application/vnd.docker.plugin.v1+json

Docker 插件安装错误

WSL 下 Docker 拉取慢:网络与挂载目录影响及优化

WSL 拉取镜像慢

轩辕镜像是否安全?镜像完整性校验(digest)说明

镜像安全性

如何用轩辕镜像拉取镜像?登录方式与专属域名配置

如何拉取镜像

错误码与失败问题

manifest unknown 错误:镜像不存在或标签错误

manifest unknown 错误

TLS/SSL 证书验证失败:Docker pull 时 HTTPS 证书错误

TLS 证书验证失败

DNS 解析超时:无法解析镜像仓库地址或连接超时

DNS 解析超时

410 Gone 错误:Docker 版本过低导致协议不兼容

410 错误:版本过低

402 Payment Required 错误:流量耗尽错误提示

402 错误:流量耗尽

401 UNAUTHORIZED 错误:身份认证失败或登录信息错误

身份认证失败错误

429 Too Many Requests 错误:请求频率超出专业版限制

429 限流错误

Docker login 凭证保存错误:Cannot autolaunch D-Bus(不影响登录)

凭证保存错误

账号 / 计费 / 权限

免费版与专业版区别:功能、限额与使用场景对比

免费版与专业版区别

支持的镜像仓库:Docker Hub、GCR、GHCR、K8s 等列表

轩辕镜像支持的镜像仓库

拉取失败是否扣流量?计费规则说明

拉取失败流量计费

KYSEC 权限不够:麒麟 V10/统信 UOS 下脚本执行被拦截

KYSEC 权限错误

如何申请开具发票?(增值税普票/专票)

开具发票

如何修改网站与仓库登录密码?

修改网站和仓库密码

配置与原理类

registry-mirrors 未生效:仍访问官方仓库或报错的原因

registry-mirrors 未生效

如何去掉镜像名称中的轩辕域名前缀?(docker tag)

去掉域名前缀

如何拉取指定架构镜像?(ARM64/AMD64 等多架构)

拉取指定架构镜像

查看全部问题→

用户好评

来自真实用户的反馈,见证轩辕镜像的优质服务

用户头像

oldzhang

运维工程师

Linux服务器

5

"Docker访问体验非常流畅,大镜像也能快速完成下载。"

轩辕镜像
镜像详情
...
cheewai/postgis
博客公告Docker 镜像公告与技术博客
热门镜像查看热门 Docker 镜像推荐
一键安装一键安装 Docker 并配置镜像源
镜像拉取问题咨询请 提交工单,官方技术交流群:1072982923。轩辕镜像所有镜像均来源于原始仓库,本站不存储、不修改、不传播任何镜像内容。
镜像拉取问题咨询请提交工单,官方技术交流群:。轩辕镜像所有镜像均来源于原始仓库,本站不存储、不修改、不传播任何镜像内容。
官方邮箱:点击复制邮箱
©2024-2026 源码跳动
官方邮箱:点击复制邮箱Copyright © 2024-2026 杭州源码跳动科技有限公司. All rights reserved.