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

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

官方QQ群: 1072982923

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

热门搜索:openclaw🔥nginx🔥redis🔥mysqlopenjdkcursorweb2apimemgraphzabbixetcdubuntucorednsjdk
postgresql
sameersbn/postgresql
自动构建
sameersbn
172 次收藏下载次数: 0状态:自动构建维护者:sameersbn仓库类型:镜像最近更新:2 年前
使用轩辕镜像,把时间还给真正重要的事。点击查看
镜像简介版本下载
使用轩辕镜像,把时间还给真正重要的事。点击查看

![Circle CI]([] ![Docker Repository on Quay.io]([]

sameersbn/postgresql:12-20200524

  • Introduction
    • Contributing
    • Issues
  • Getting started
    • Installation
    • Quickstart
    • Persistence
    • Trusting local connections
    • Setting postgres user password
    • Creating database user
    • Creating databases
    • Granting user access to a database
    • Enabling extensions
    • Creating replication user
    • Setting up a replication cluster
    • Creating a snapshot
    • Creating a backup
    • Command-line arguments
    • Logs
    • UID/GID mapping
  • Maintenance
    • Upgrading
    • Shell Access

Introduction

Dockerfile to create a Docker container image for PostgreSQL.

PostgreSQL is an object-relational database management system (ORDBMS) with an emphasis on extensibility and standards-compliance [source].

Contributing

If you find this image useful here's how you can help:

  • Send a pull request with your awesome features and bug fixes
  • Help users resolve their issues.
  • Support the development of this image with a ***

Issues

Before reporting your issue please try updating Docker to the latest version and check if it resolves the issue. Refer to the Docker installation guide for instructions.

SELinux users should try disabling SELinux using the command setenforce 0 to see if it resolves the issue.

If the above recommendations do not help then report your issue along with the following information:

  • Output of the docker vers6 and docker info commands
  • The docker run command or docker-compose.yml used to start the image. Mask out the sensitive bits.
  • Please state if you are using Boot2Docker, VirtualBox, etc.

Getting started

Installation

Automated builds of the image are available on Dockerhub and is the recommended method of installation.

Note: Builds are also available on Quay.io

bash
docker pull sameersbn/postgresql:12-20200524

Alternatively you can build the image yourself.

bash
docker build -t sameersbn/postgresql github.com/sameersbn/docker-postgresql

Quickstart

Start PostgreSQL using:

bash
docker run --name postgresql -itd --restart always \
  --publish 5432:5432 \
  --volume postgresql:/var/lib/postgresql \
  sameersbn/postgresql:12-20200524

Login to the PostgreSQL server using:

bash
docker exec -it postgresql sudo -u postgres psql

Alternatively, you can use the sample docker-compose.yml file to start the container using Docker Compose

Persistence

For PostgreSQL to preserve its state across container shutdown and startup you should mount a volume at /var/lib/postgresql. If you don't like the default volume destination then you can change it

The Quickstart command already mounts a volume for persistence.

SELinux users should update the security context of the host mountpoint so that it plays nicely with Docker:

bash
mkdir -p /srv/docker/postgresql
chcon -Rt svirt_sandbox_file_t /srv/docker/postgresql

Trusting local connections

By default connections to the PostgreSQL server need to authenticated using a password. If desired you can trust connections from the local network using the PG_TRUST_LOCALNET variable.

bash
docker run --name postgresql -itd --restart always \
  --env 'PG_TRUST_LOCALNET=true' \
  sameersbn/postgresql:12-20200524

Note

The local network here is network to which the container is attached. This has different meanings depending on the --net parameter specified while starting the container. In the default configuration, this parameter would trust connections from other containers on the docker0 bridge.

Setting postgres user password

By default the postgres user is not assigned a password and as a result you can only login to the PostgreSQL server locally. If you wish to login remotely to the PostgreSQL server as the postgres user, you will need to assign a password for the user using the PG_PASSWORD variable.

bash
docker run --name postgresql -itd --restart always \
  --env 'PG_PASSWORD=passw0rd' \
  sameersbn/postgresql:12-20200524

Note

  • When persistence is in use, PG_PASSWORD is effective on the first run.
  • This feature is only available in the latest and versions > 9.4-10

Creating database user

A new PostgreSQL database user can be created by specifying the DB_USER and DB_PASS variables while starting the container.

bash
docker run --name postgresql -itd --restart always \
  --env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' \
  sameersbn/postgresql:12-20200524

Notes

  • The created user can login remotely
  • The container will error out if a password is not specified for the user
  • No changes will be made if the user already exists
  • Only a single user can be created at each launch

Creating databases

A new PostgreSQL database can be created by specifying the DB_NAME variable while starting the container.

bash
docker run --name postgresql -itd --restart always \
  --env 'DB_NAME=dbname' \
  sameersbn/postgresql:12-20200524

By default databases are created by copying the standard system database named template1. You can specify a different template for your database using the DB_TEMPLATE parameter. Refer to Template Databases for further information.

Additionally, more than one database can be created by specifying a comma separated list of database names in DB_NAME. For example, the following command creates two new databases named dbname1 and dbname2.

This feature is only available in releases greater than 9.1-1

bash
docker run --name postgresql -itd --restart always \
  --env 'DB_NAME=dbname1,dbname2' \
  sameersbn/postgresql:12-20200524

Granting user access to a database

If the DB_USER and DB_PASS variables are specified along with the DB_NAME variable, then the user specified in DB_USER will be granted access to all the databases listed in DB_NAME. Note that if the user and/or databases do not exist, they will be created.

bash
docker run --name postgresql -itd --restart always \
  --env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' \
  --env 'DB_NAME=dbname1,dbname2' \
  sameersbn/postgresql:12-20200524

In the above example dbuser with be granted access to both the dbname1 and dbname2 databases.

Enabling extensions

The image also packages the postgres contrib module. A comma separated list of modules can be specified using the DB_EXTENSION parameter.

bash
docker run --name postgresql -itd \
  --env 'DB_NAME=db1,db2' --env 'DB_EXTENSION=unaccent,pg_trgm' \
  sameersbn/postgresql:12-20200524

The above command enables the unaccent and pg_trgm modules on the databases listed in DB_NAME, namely db1 and db2.

NOTE:

This option deprecates the DB_UNACCENT parameter.

Creating replication user

Similar to the creation of a database user, a new PostgreSQL replication user can be created by specifying the REPLICATION_USER and REPLICATION_PASS variables while starting the container.

bash
docker run --name postgresql -itd --restart always \
  --env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
  sameersbn/postgresql:12-20200524

Notes

  • The created user can login remotely
  • The container will error out if a password is not specified for the user
  • No changes will be made if the user already exists
  • Only a single user can be created at each launch

It is a good idea to create a replication user even if you are not going to use it as it will allow you to setup slave nodes and/or generate snapshots and backups when the need arises.

Setting up a replication cluster

When the container is started, it is by default configured to act as a master node in a replication cluster. This means that you can scale your PostgreSQL database backend when the need arises without incurring any downtime. However do note that a replication user must exist on the master node for this to work.

Begin by creating the master node of our cluster:

bash
docker run --name postgresql-master -itd --restart always \
  --env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' --env 'DB_NAME=dbname' \
  --env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
  sameersbn/postgresql:12-20200524

Notice that no additional arguments are specified while starting the master node of the cluster.

To create a replication slave the REPLICATION_MODE variable should be set to slave and additionally the REPLICATION_HOST, REPLICATION_PORT, REPLICATION_SSLMODE, REPLICATION_USER and REPLICATION_PASS variables should be specified.

Create a slave node:

bash
docker run --name postgresql-slave01 -itd --restart always \
  --link postgresql-master:master \
  --env 'REPLICATION_MODE=slave' --env 'REPLICATION_SSLMODE=prefer' \
  --env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432'  \
  --env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
  sameersbn/postgresql:12-20200524

In the above command, we used docker links so that we can address the master node using the master alias in REPLICATION_HOST.

Note

  • The default value of REPLICATION_PORT is 5432
  • The default value of REPLICATION_SSLMODE is prefer
  • The value of REPLICATION_USER and REPLICATION_PASS should be the same as the ones specified on the master node.
  • With persistence in use, if the container is stopped and started, for the container continue to function as a slave you need to ensure that REPLICATION_MODE=slave is defined in the containers environment. In the absense of which the slave configuration will be turned off and the node will allow writing to it while having the last synced data from the master.

And just like that with minimal effort you have a PostgreSQL replication cluster setup. You can create additional slaves to scale the cluster horizontally.

Here are some important notes about a PostgreSQL replication cluster:

  • Writes can only occur on the master
  • Slaves are read-only
  • For best performance, limit the reads to the slave nodes

Creating a snapshot

Similar to a creating replication slave node, you can create a snapshot of the master by specifying REPLICATION_MODE=snapshot.

Once the master node is created as specified in Setting up a replication cluster, you can create a snapshot using:

bash
docker run --name postgresql-snapshot -itd --restart always \
  --link postgresql-master:master \
  --env 'REPLICATION_MODE=snapshot' --env 'REPLICATION_SSLMODE=prefer' \
  --env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432'  \
  --env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
  sameersbn/postgresql:12-20200524

The difference between a slave and a snapshot is that a slave is read-only and updated whenever the master data is updated (streaming replication), while a snapshot is read-write and is not updated after the initial snapshot of the data from the master.

This is useful for developers to quickly snapshot the current state of a live database and use it for development/debugging purposes without altering the database on the live instance.

Creating a backup

Just as the case of setting up a slave node or generating a snapshot, you can also create a backup of the data on the master by specifying REPLICATION_MODE=backup.

The backups are generated with pg_basebackup using the replication protocol.

Once the master node is created as specified in Setting up a replication cluster, you can create a point-in-time backup using:

bash
docker run --name postgresql-backup -it --rm \
  --link postgresql-master:master \
  --env 'REPLICATION_MODE=backup' --env 'REPLICATION_SSLMODE=prefer' \
  --env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432'  \
  --env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
  --volume /srv/docker/backups/postgresql.$(date +%Y%m%d%H%M%S):/var/lib/postgresql \
  sameersbn/postgresql:12-20200524

Once the backup is generated, the container will exit and the backup of the master data will be available at /srv/docker/backups/postgresql.XXXXXXXXXXXX/. Restoring the backup involves starting a container with the data in /srv/docker/backups/postgresql.XXXXXXXXXXXX.

Command-line arguments

You can customize the launch command of PostgreSQL server by specifying arguments for postgres on the docker run command. For example the following command enables connection logging:

bash
docker run --name postgresql -itd --restart always \
  sameersbn/postgresql:12-20200524 -c log_connections=on

Please refer to the documentation of postgres for the complete list of available options.

Logs

By default the PostgreSQL server logs are sent to the standard output. Using the Command-line arguments feature you can configure the PostgreSQL server to send the log output to a file using the -c logging_collector=on argument:

bash
docker run --name postgresql -itd --restart always \
  sameersbn/postgresql:12-20200524 -c logging_collector=on

To access the PostgreSQL logs you can use docker exec. For example:

bash
docker exec -it postgresql tail -f /var/log/postgresql/postgresql-9.4-main.log

UID/GID mapping

The files and processes created by the container are owned by the postgres user that is internal to the container. In the absense of user namespace in docker the UID and GID of the containers postgres user may have different meaning on the host.

For example, a user on the host with the same UID and/or GID as the postgres user of the container will be able to access the data in the persistent volumes mounted from the host as well as be able to KILL the postgres server process started by the container.

To circumvent this issue you can specify the UID and GID for the postgres user of the container using the USERMAP_UID and USERMAP_GID variables respectively.

For example, if you want to assign the postgres user of the container the UID and GID 999:

bash
docker run --name postgresql -itd --restart always \
  --env 'USERMAP_UID=999' --env 'USERMAP_GID=999' \
  sameersbn/postgresql:12-20200524

Maintenance

Upgrading

To upgrade to newer releases:

  1. Download the updated Docker image:
bash
docker pull sameersbn/postgresql:12-20200524
  1. Stop the currently running image:
bash
docker stop postgresql
  1. Remove the stopped container
bash
docker rm -v postgresql
  1. Start the updated image
bash
docker run --name postgresql -itd \
  [OPTIONS] \
  sameersbn/postgresql:12-20200524

Shell Access

For debugging and maintenance purposes you may want access the containers shell. If you are using Docker version 1.3.0 or higher you can access a running containers shell by starting bash using docker exec:

bash
docker exec -it postgresql bash
查看更多 postgresql 相关镜像 →
bitnami/postgresql logo
bitnami/postgresql
bitnami
Bitnami PostgreSQL安全镜像是一款专为PostgreSQL数据库设计的预配置、安全强化型容器镜像,集成自动更新的安全补丁、最小化攻击面架构、合规性验证工具及行业最佳安全实践,旨在简化数据库部署流程,同时保障数据存储与访问的安全性、稳定性及可靠性,适用于企业级应用场景下高效、安全的数据库环境搭建。
374 次收藏10亿+ 次下载
27 天前更新
bitnamicharts/postgresql logo
bitnamicharts/postgresql
bitnamicharts
Bitnami的PostgreSQL Helm chart,用于在Kubernetes环境中便捷部署和管理PostgreSQL数据库,支持灵活配置与可靠运行。
5 次收藏1000万+ 次下载
21 天前更新
manageiq/postgresql logo
manageiq/postgresql
manageiq
基于CentOS构建的PostgreSQL容器,专为ManageIQ平台设计,提供可靠的后端数据库服务支持。
100万+ 次下载
24 天前更新
vmware/postgresql logo
vmware/postgresql
vmware
暂无描述
2 次收藏5万+ 次下载
8 年前更新
corpusops/postgresql logo
corpusops/postgresql
corpusops
postgresql image
1万+ 次下载
6 年前更新
islandora/postgresql logo
islandora/postgresql
islandora
开源关系型数据库。
5万+ 次下载
22 天前更新

轩辕镜像配置手册

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

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访问体验非常流畅,大镜像也能快速完成下载。"

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