📚 开源资源分享——颜佐光的个人书架
✉️ 联系站长
书架 / 数据库 / 安装

docker安装postgresql

2020-04-05 11:39 · 约 1,119 字 · 浏览 2,707 次 · 更新 2020-05-17 10:19安装

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

← 返回《数据库》目录书架 →