1.docker pull docker.io/postgres:11
2.启动命令脚本
vi startPostgres.sh
填入以下内容:
docker run -d --name postgresql-11 \
--restart=always \
-v /postgresql/data:/var/lib/postgresql/data \
-e POSTGRES_PASSWORD=123456 \
-p 5432:5432 \
docker.io/postgres:11
3.给脚本写权限:
chmod +x startPostgres.sh
4.执行启动脚本:
./startPostgres.sh
5.查看日志,启动报错:
docker logs postgresql-11
2019-06-13 12:35:21.977 UTC [1] FATAL: configuration file "/var/lib/postgresql/data/postgresql.conf" contains errors
2019-06-13 12:35:23.182 UTC [1] LOG: invalid value for parameter "lc_messages": "zh_CN.UTF-8"
2019-06-13 12:35:23.182 UTC [1] LOG: invalid value for parameter "lc_monetary": "zh_CN.UTF-8"
2019-06-13 12:35:23.182 UTC [1] LOG: invalid value for parameter "lc_numeric": "zh_CN.UTF-8"
2019-06-13 12:35:23.182 UTC [1] LOG: invalid value for parameter "lc_time": "zh_CN.UTF-8"
6.在容器中安装中文编码:
>>docker exec -it postgresql-11 /bin/bash
1、root@9a36f3d4c0e9:/# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
2、debian下安装 locale 并设置 zh_CN.UTF-8
root@9a36f3d4c0e9:/# apt-get install locales
Reading package lists... Done
Building dependency tree
Reading state information... Done
locales is already the newest version (2.24-11+deb9u4).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
3、root@9a36f3d4c0e9:/# dpkg-reconfigure locales
Locales to be generated: 468
Default locale for the system environment: 3
Generating locales (this might take a while)...
zh_CN.UTF-8... done
Generation complete.
7.重启动docker容器:
doker start postgresql-11