美文网首页
docker安装 postgres (ubuntu)

docker安装 postgres (ubuntu)

作者: 一介书生独醉江湖 | 来源:发表于2023-11-15 10:17 被阅读0次
# 下载镜像
ds@ds-virtual-machine:~$ docker pull postgres

# 创建目录
ds@ds-virtual-machine:~$ sudo mkdir /opt/pg-data

# docker运行
ds@ds-virtual-machine:~$ docker run -itd -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgrespw -p 5432:5432 -v /opt/pg-data:/var/lib/postgresql/data --name postgres postgres

# 进入容器
ds@ds-virtual-machine:~$ docker exec -it postgres bash

# 登录
root@2b24edd84c92:/# PGPASSWORD=postgrespw psql -U postgres

# 创建数据库
postgres=# create database fabricexplorer owner=postgres;
CREATE DATABASE

# 创建SCHEMA并赋权给postgres
postgres=# create schema if not exists pms authorization postgres;
CREATE SCHEMA

# 查询已创建的数据库
postgres=# \l
                                                         List of databases
      Name      |  Owner   | Encoding | Locale Provider |  Collate   |   Ctype    | ICU Locale | ICU Rules |   Acc
ess privileges   
----------------+----------+----------+-----------------+------------+------------+------------+-----------+------
-----------------
 fabricexplorer | postgres | UTF8     | libc            | en_US.utf8 | en_US.utf8 |            |           | 
 postgres       | postgres | UTF8     | libc            | en_US.utf8 | en_US.utf8 |            |           | 
 template0      | postgres | UTF8     | libc            | en_US.utf8 | en_US.utf8 |            |           | =c/po
stgres          +
                |          |          |                 |            |            |            |           | postg
res=CTc/postgres
 template1      | postgres | UTF8     | libc            | en_US.utf8 | en_US.utf8 |            |           | =c/po
stgres          +
                |          |          |                 |            |            |            |           | postg
res=CTc/postgres
 

image.png
# 其他
# 根据卷驱动和镜像,重启postgres
docker run --name postgres-container -v prod-pg0-data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=postgres -d postgres
参考:
https://blog.csdn.net/Young4Dream/article/details/129679076

相关文章

网友评论

      本文标题:docker安装 postgres (ubuntu)

      本文链接:https://www.haomeiwen.com/subject/trmjwdtx.html