postgres镜像使用

拉取docker镜像并拉起

docker pull postgres:12
docker run --name postgresql --restart always -p 5432:5432 -e POSTGRES_PASSWORD=123456 -d postgres:12

进入docker并操作数据库

# 进入docker
docker exec -ti `docker ps | grep postgres | awk '{print$1}'` /bin/bash
# 登陆postgres数据库
psql -U postgres
# 查看数据库中的database
\l
# 创建数据库
CREATE DATABASE xxx;
# 选择
\c xxx
# 增加字段
alter table xxx add column exp_time date;
# 退出数据库
\q 
# 退出镜像
exit 

猜你喜欢

转载自blog.csdn.net/weixin_46248273/article/details/120175337