# 下載鏡像
ds@ds-virtual-machine:~$ docker pull postgres
# 創(chuàng)建目錄
ds@ds-virtual-machine:~$ sudo mkdir /opt/pg-data
# docker運(yùn)行
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
# 進(jìn)入容器
ds@ds-virtual-machine:~$ docker exec -it postgres bash
# 登錄
root@2b24edd84c92:/# PGPASSWORD=postgrespw psql -U postgres
# 創(chuàng)建數(shù)據(jù)庫
postgres=# create database fabricexplorer owner=postgres;
CREATE DATABASE
# 創(chuàng)建SCHEMA并賦權(quán)給postgres
postgres=# create schema if not exists pms authorization postgres;
CREATE SCHEMA
# 查詢已創(chuàng)建的數(shù)據(jù)庫
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
# 其他
# 根據(jù)卷驅(qū)動(dòng)和鏡像,重啟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
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者