Docker-10:Docker安装PostgreSQL

1. 前提

postgreSQL

Docker

由于在安装过程中,需要获取 PostgreSQL 的镜像,所以请及时 [[Docker安装及更换源]]。

2. 下载PostgreSQL镜像

2.1. 检索当前镜像


$ docker search postgres

20220705152209

列名列描述
NAME镜像名称
DESCRIPTION镜像描述
STARS标星数
OFFICIAL官方的
AUTOMATED自动化

话不多说,肯定选官方提供的镜像,同事它也是标星数量最多的。

2.2. 拉取当前镜像

不带版本号,代表为当前阶段最新的,如果需要指定的版本,请使用 docker pull postgres:${VERSION} 其中 ${VERSION} 代表你需要的版本号。

此处演示需要直接用最新版本。


$ docker pull postgres

pull 镜像后,查看镜像


$ docker images

20220705152846

3. 创建挂载文件夹

在运行 Docker 的系统中,创建一个可以挂在 PostgreSQL 数据文件的地方,方便后面做数据迁移等工作。

此处演示需要,使用了 /data/postgres 当作挂在文件的目录。


[root@localhost ~]$ cd /data/
[root@localhost data]$ mkdir postgres
[root@localhost postgres]$ pwd
/data/postgres

4. 启动镜像


docker run --name postgresql --privileged -e POSTGRES_PASSWORD=password -p 15433:5432 -v /data/postgres:/var/lib/postgresql/data -d postgres

4.1. 查看日志

20220705155606


PostgreSQL Database directory appears to contain a database; Skipping initialization

2022-07-05 07:36:51.259 UTC [1] LOG:  starting PostgreSQL 14.1 (Debian 14.1-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-07-05 07:36:51.261 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2022-07-05 07:36:51.261 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2022-07-05 07:36:51.264 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-07-05 07:36:51.271 UTC [26] LOG:  database system was interrupted; last known up at 2022-07-05 07:24:38 UTC
2022-07-05 07:36:51.292 UTC [26] LOG:  database system was not properly shut down; automatic recovery in progress
2022-07-05 07:36:51.294 UTC [26] LOG:  redo starts at 0/16FAFF0

4.2. 查看进程


docker ps -a

20220705154046

5. 使用连接

测试数据库是否连接成功,用户名为 postgres;密码为: password。

20220705155631

20220705155819

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王老邪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值