使用ubi容器的postgresql

先登陆到RH

1
2
3
4
5
6
# subscription-manager register
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: ********
Password: **********

# podman login registry.redhat.io

新建数据库运行路径,并设置权限

1
2
3
mkdir -p /data/psql/datebase
mkdir -p /data/psql/log
chown -R 26:26 /data/psql/

制作一个Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
FROM registry.redhat.io/ubi8/ubi
RUN yum -y install bash-completion nano net-tools iputils && \
yum -y module enable postgresql:12 && \
yum -y module install postgresql && \
yum clean all
RUN usermod -a -G root postgres && \
mkdir -p /var/lib/pgsql/data && \
chown -R postgres:postgres /var/lib/pgsql/data && \
chmod 777 /var/lib/pgsql/data

USER 26
VOLUME ["/var/lib/pgsql/data"]
EXPOSE 5432
STOPSIGNAL SIGINT

CMD ["postgres","-D","/var/lib/pgsql/data"]

使用buildah构建image

1
buildah bud -t psql:$(date +%Y%m%d%H%M%S) .

初始化数据库(以后升级不再需要)

1
2
3
4
5
6
7
8
9
10
podman run --rm -it \
-p 5432:5432 \
-v /data/psql/log:/var/log \
-v /data/psql/datebase:/var/lib/pgsql/data \
localhost/psql:20210627192640 \
/bin/bash


# 进入容器后执行
initdb -D /var/lib/pgsql/data

新建并运行容器

1
2
3
4
5
6
7
8
9
10
podman create  \
-p 5432:5432 \
-v /data/psql/log:/var/log \
-v /data/psql/datebase:/var/lib/pgsql/data \
--name=PostgreSQL \
localhost/psql:20210627192640


podman start PostgreSQL