docker postgres使用

1、拉取镜像文件docker pull postgres

2、容器后台进程运行,向外暴露5432端口

  docker run --name mypostgres -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 postgres

  运行成功后默认数据库登录名、密码皆为postgres,当然也可以手动设置登录名、密码

  

3、使用postgres客户端登录测试,这里使用的客户端是DataGrip

4、进入容器内部,使用postgres cli命令

  4.1 默认起手式 docker exec -it [mypostgres] /bin/bash

  4.2 psql -U postgres -W 使用密码登录

  4.3 使用psql --help可查看所有cli命令

附上psql cli命令文档:https://postgrescheatsheet.com/#/databases

原文地址:https://www.cnblogs.com/az4215/p/11915249.html