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
本文由 创作,采用 知识共享署名4.0 国际许可协议进行许可。本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为: 2020/05/17 02:19