docker安装postgresql
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
posted on 2019-11-11 15:11 SmilingEye 阅读(3495) 评论(0) 编辑 收藏 举报