Docker 运行 PolarDB-for-PostgreSQL 的命令,并已包含数据持久化配置

拉取官方 Docker 镜像

从 Docker Hub 拉取 PolarDB-for-PostgreSQL 的官方镜像。

bash 复制代码
docker pull polardb/polardb_pg_local_instance

如果无法拉去使用本人的阿里云的

x86架构

bash 复制代码
docker pull registry.cn-hangzhou.aliyuncs.com/qiluo-images/polardb_pg_local_instance:latest

ARM架构的

bash 复制代码
docker pull registry.cn-hangzhou.aliyuncs.com/qiluo-images/linux_arm64_polardb_pg_local_instance:latest
bash 复制代码
docker run -d \
    --name polardb_pg_prod \
    --restart=unless-stopped \
    --cpus=4 \
    --memory=8g \
    --memory-swap=9g \
    --shm-size=1g \
    -p 32682:5432 \
    -e LANG=C.UTF-8 \
    -e TZ=Asia/Shanghai \
    -e POSTGRES_USER=polardb_admin \
    -e POSTGRES_PASSWORD=JmpBqVaqky2auE9k \
    -e POSTGRES_DB=polardb_prod \
    -v /data/polardb/data:/var/lib/postgresql/data \
    -v /data/polardb/backups:/backups \
    -v /data/polardb/conf:/etc/postgresql \
    -v /etc/localtime:/etc/localtime:ro \
    --health-cmd="pg_isready -U polardb_admin" \
    --health-interval=30s \
    --health-timeout=10s \
    --health-retries=3 \
    registry.cn-hangzhou.aliyuncs.com/qiluo-images/polardb_pg_local_instance:latest

生产环境增强配置说明:

资源限制:

--cpus=4:限制容器使用最多 4 个 CPU 核心

--memory=8g:限制容器使用最大 8GB 内存

--memory-swap=9g:设置交换分区大小

--shm-size=1g:增加共享内存大小,对 PostgreSQL 性能很重要

自动重启:

--restart=unless-stopped:Docker 守护进程重启时自动重启容器,除非手动停止

安全认证:

-e POSTGRES_PASSWORD=JmpBqVaqky2auE9k:务必修改为强密码

-e POSTGRES_USER=polardb_admin:创建指定管理员用户

-e POSTGRES_DB=polardb_prod:创建指定数据库

多卷挂载:

-v /data/polardb/data:/var/lib/postgresql/data:主数据目录

-v /data/polardb/backups:/backups:备份目录

-v /data/polardb/conf:/etc/postgresql:配置文件目录(方便自定义配置)

-v /etc/localtime:/etc/localtime:ro:保持容器时间与主机同步

健康检查:

--health-cmd 等参数:配置容器健康检查,便于监控和自动恢复

连接示例:

使用 psql 连接

bash 复制代码
psql -h localhost -p 32682 -U polardb_admin -d polardb_prod

或者使用连接字符串

bash 复制代码
psql "postgresql://polardb_admin:JmpBqVaqky2auE9k @localhost:32682/polardb_prod"
相关推荐
虎头金猫2 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
分布式存储与RustFS2 天前
MinIO 官方 Docker 镜像被移除:依赖它的项目该怎么办
docker·云原生·devops·对象存储·minio·分布式存储
geovindu2 天前
sql: Transaction & Concurrency Patterns using postgresql 18
postgresql·数据库开发·数据库架构
玉&心2 天前
通过Arthas在线诊断K8S中的内存及JVM等使用情况
docker·k8s·arthas
xing-xing2 天前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
赵文宇(温玉)2 天前
CoreDNS的hosts插件的缺行配置导致k8s集群异常
容器·kubernetes·rancher
guo_wen_qiang2 天前
上传本地镜像到harbor中
docker·容器·持续部署
羑悻的小杀马特2 天前
Dockerfile 全景指南:从入门编写dockerfile到生产环境镜像优化实战,一步步带你从啃透制作指令到镜像制作落地!
docker·dockerfile·镜像制作
BianHuanShiZhe2 天前
docker常见命令
docker
thinking_talk2 天前
WorkBuddy应用生成背后的数据层:腾讯云PG
postgresql·腾讯云·云数据库