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