添加“获取最新版本pgsql+timescaleb的dockerfile”
This commit is contained in:
41
docker/Dockerfile/pgsql+timescale/dockerfile
Normal file
41
docker/Dockerfile/pgsql+timescale/dockerfile
Normal file
@ -0,0 +1,41 @@
|
||||
# 使用官方 PostgreSQL 最新版本镜像作为基础镜像
|
||||
FROM postgres:latest
|
||||
|
||||
# 设置环境变量,用于 PostgreSQL 初始化
|
||||
ENV POSTGRES_USER=postgres
|
||||
ENV POSTGRES_PASSWORD=yhsoft@ecs
|
||||
ENV POSTGRES_DB=postgres
|
||||
|
||||
# 安装必要的依赖
|
||||
RUN apt-get update && apt-get install -y wget gnupg lsb-release
|
||||
|
||||
# 获取当前系统的发行版代号
|
||||
RUN DISTRO=$(lsb_release -c -s) && \
|
||||
# 添加 TimescaleDB 软件源和 GPG 密钥
|
||||
wget -q -O - https://packagecloud.io/timescale/timescaledb/gpgkey | apt-key add - && \
|
||||
echo "deb https://packagecloud.io/timescale/timescaledb/debian/ $DISTRO main" > /etc/apt/sources.list.d/timescaledb.list
|
||||
|
||||
# 检查文件是否正确生成
|
||||
RUN cat /etc/apt/sources.list.d/timescaledb.list
|
||||
|
||||
# 更新包列表
|
||||
RUN apt-get update
|
||||
|
||||
# 获取最新的 PostgreSQL 版本号
|
||||
RUN PG_VERSION=$(pg_config --version | grep -oE '[0-9]+' | head -n 1) && \
|
||||
# 安装与最新 PostgreSQL 版本兼容的 TimescaleDB
|
||||
apt-get install -y timescaledb-2-postgresql-$PG_VERSION
|
||||
|
||||
# 创建一个脚本,在容器启动时修改配置文件
|
||||
RUN echo '#!/bin/bash' > /docker-entrypoint-initdb.d/setup.sh && \
|
||||
echo 'while [ ! -f /var/lib/postgresql/data/postgresql.conf ]; do' >> /docker-entrypoint-initdb.d/setup.sh && \
|
||||
echo ' sleep 1' >> /docker-entrypoint-initdb.d/setup.sh && \
|
||||
echo 'done' >> /docker-entrypoint-initdb.d/setup.sh && \
|
||||
echo "echo \"shared_preload_libraries = 'timescaledb'\" >> /var/lib/postgresql/data/postgresql.conf" >> /docker-entrypoint-initdb.d/setup.sh && \
|
||||
chmod +x /docker-entrypoint-initdb.d/setup.sh
|
||||
|
||||
# 暴露 PostgreSQL 默认端口
|
||||
EXPOSE 5432
|
||||
|
||||
# 容器启动时执行的命令,启动 PostgreSQL 服务
|
||||
CMD ["postgres"]
|
Reference in New Issue
Block a user