Ubuntu 20.04 postgresql
安装命令
$ sudo apt-get update
$ sudo apt-get install -y postgresql
查看postgresql版本
$ psql --version
psql (PostgreSQL) 12.22 (Ubuntu 12.22-0ubuntu0.20.04.3)
查看系统用户组是否存在postgres
$ getent group postgres
postgres:x:115:
$ getent passwd postgres
postgres:x:107:115:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
修改postgres USER密码
$ sudo -i -u postgres
[sudo] password for pi:
$ psql
postgres=# ALTER USER postgres WITH PASSWORD '123456';
ALTER ROLE
根据sql导入数据库
$ sudo -u postgres psql -d postgres -f ./pg_initial.sql
Dockerfile
使用alphine所构建出的docker image尺寸较小
FROM postgres:alpine3.19COPY docker-entrypoint.sh /usr/local/bin/
ADD pg_initial.sql /docker-entrypoint-initdb.d/
RUN chmod 0777 /docker-entrypoint-initdb.d/pg_initial.sql && chown postgres:postgres /docker-entrypoint-initdb.d/pg_initial.sqlEXPOSE 5432