From 6d8f4e96dcb7e3eab53160a6406d50bd582a01dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AB=A5=E4=B8=BD=E7=84=B6?= Date: Tue, 24 Jun 2025 10:34:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E2=80=9C=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=89=88=E6=9C=ACpgsql+timescaleb=E7=9A=84do?= =?UTF-8?q?ckerfile=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/Dockerfile/pgsql+timescale/dockerfile | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 docker/Dockerfile/pgsql+timescale/dockerfile diff --git a/docker/Dockerfile/pgsql+timescale/dockerfile b/docker/Dockerfile/pgsql+timescale/dockerfile new file mode 100644 index 0000000..1a92ab5 --- /dev/null +++ b/docker/Dockerfile/pgsql+timescale/dockerfile @@ -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"] \ No newline at end of file