惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
小众软件
小众软件
The Cloudflare Blog
S
SegmentFault 最新的问题
美团技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
阮一峰的网络日志
阮一峰的网络日志
博客园 - 聂微东
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
雷峰网
雷峰网
WordPress大学
WordPress大学
T
Tailwind CSS Blog
腾讯CDC
人人都是产品经理
人人都是产品经理
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
M
MIT News - Artificial intelligence
D
DataBreaches.Net
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
J
Java Code Geeks
宝玉的分享
宝玉的分享

博客园 - SmilingEye

每天5分钟,用碎片时间搞定软考系统架构设计师600词 2025年9月Java后端招聘市场技术风向标:666份招聘数据深度解读 微信小程序PDF签名 DBLock 面试题:ReentrantLock 实现原理 docker 升级(软件包离线方式) tomcat设置https 使用fastjson时spring security oauth2获取token格式变化 springboot之cookie操作 使用sed将win换行符转linux与linux换行符转win linux修改权限后git pull出现冲突 JWT简介 jenkins之SSH Publishers连接windows Windows安装OpenSSH服务 jenkins从远程服务器下载 重写mybatis的字符串类型处理器 mybatis-sqlite日期类型对应关系 docker常用命令 java sqlite docker,sqlite出错
docker安装postgresql
SmilingEye · 2019-11-11 · via 博客园 - SmilingEye

1.在linux执行以下代码:

docker run -p 5432:5432 -v /home/docker/postgresql/data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=postgres -e TZ=PRC -d --name=some-postgres postgres:11.5-alpine

-p端口映射

-v将数据存到宿主服务器

-e POSTGRES_PASSWORD 密码(默认用户名postgres)

-e TZ=PRC时区,中国

-d后台运行

--name容器名称

2.时区问题

如果在启动容器时不设置时区,默认为UTC,使用now()设置默认值的时候将有时间差。

select now();
show time zone;

在设置环境变量时,提示:

Warning: the Docker specific variables will only have an effect if you start the container with a data directory that is empty; any pre-existing database will be left untouched on container startup.

意思是:数据目录为空时,设置环境变量有效;数据目录不为空时,将使用数据目录设置的环境变量,将保持不变。

例如上面代码的宿主服务器/home/docker/postgresql/data就是数据目录。

3.参考

dockerhub安装说明

https://hub.docker.com/_/postgres?tab=description

使用非docker安装postgresql安装设置时区,对docker安装可以参考,例如:postgresql.conf配置在宿主服务器/home/docker/postgresql/data下,设置同样有效

https://blog.csdn.net/max1124/article/details/78410315

https://github.com/docker-library/postgres/issues/137#issuecomment-217064811

https://www.postgresql.org/docs/9.5/app-initdb.html