Update Dockerfile
Browse files- Dockerfile +7 -13
Dockerfile
CHANGED
@@ -44,7 +44,7 @@ ENV POSTGRES_USER=${POSTGRES_USER} \
|
|
44 |
COPY requirements.txt ${WORKDIR}/requirements.txt
|
45 |
COPY package.json ${WORKDIR}/package.json
|
46 |
|
47 |
-
# 安装必要的软件包、Node.js,Python,并设置时区,清理apt缓存以减少镜像大小
|
48 |
RUN apt-get update && apt-get install -y \
|
49 |
curl unzip gnupg build-essential sudo vim git procps lsof net-tools \
|
50 |
ca-certificates openssl tzdata python3 python3-venv python3-pip gosu \
|
@@ -58,7 +58,7 @@ RUN apt-get update && apt-get install -y \
|
|
58 |
python3 -m venv $VIRTUAL_ENV && \
|
59 |
$VIRTUAL_ENV/bin/pip install --upgrade pip && \
|
60 |
$VIRTUAL_ENV/bin/pip install -r ${WORKDIR}/requirements.txt && \
|
61 |
-
npm install
|
62 |
|
63 |
# 设置工作目录并复制脚本
|
64 |
WORKDIR ${WORKDIR}
|
@@ -68,28 +68,22 @@ COPY backup.sh ${WORKDIR}/backup.sh
|
|
68 |
|
69 |
RUN chmod +x ${WORKDIR}/run.sh ${WORKDIR}/import-db.sh ${WORKDIR}/backup.sh
|
70 |
|
71 |
-
# 更改 postgres 用户 UID 和 GID 为 1000
|
72 |
USER root
|
73 |
RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \
|
74 |
chown -R postgres:postgres /var/lib/postgresql /var/run/postgresql ${WORKDIR} && \
|
75 |
-
mkdir -p ${WORKDIR}/backups && chmod -R 775 ${WORKDIR}/backups
|
|
|
76 |
|
77 |
# 设置定期备份任务:每4小时运行一次备份任务
|
78 |
RUN echo "0 */1 * * * /app/backup.sh" > /etc/cron.d/backup && \
|
79 |
chmod 0644 /etc/cron.d/backup && crontab /etc/cron.d/backup
|
80 |
|
81 |
-
|
82 |
# 切换到 postgres 用户
|
83 |
USER postgres
|
84 |
|
85 |
-
# 分离 PostgreSQL 和 n8n 健康检查
|
86 |
-
HEALTHCHECK --interval=120s --timeout=10s --start-period=10s --retries=3 \
|
87 |
-
CMD pg_isready || exit 1
|
88 |
-
HEALTHCHECK --interval=120s --timeout=10s --start-period=10s --retries=3 \
|
89 |
-
CMD curl -f http://localhost:7860/HEALTHZ || exit 1
|
90 |
-
|
91 |
# 暴露 n8n 服务端口
|
92 |
EXPOSE 7860
|
93 |
|
94 |
-
#
|
95 |
-
CMD
|
|
|
44 |
COPY requirements.txt ${WORKDIR}/requirements.txt
|
45 |
COPY package.json ${WORKDIR}/package.json
|
46 |
|
47 |
+
# 安装必要的软件包、Node.js,Python,并设置时区,清理 apt 缓存以减少镜像大小
|
48 |
RUN apt-get update && apt-get install -y \
|
49 |
curl unzip gnupg build-essential sudo vim git procps lsof net-tools \
|
50 |
ca-certificates openssl tzdata python3 python3-venv python3-pip gosu \
|
|
|
58 |
python3 -m venv $VIRTUAL_ENV && \
|
59 |
$VIRTUAL_ENV/bin/pip install --upgrade pip && \
|
60 |
$VIRTUAL_ENV/bin/pip install -r ${WORKDIR}/requirements.txt && \
|
61 |
+
npm install --production
|
62 |
|
63 |
# 设置工作目录并复制脚本
|
64 |
WORKDIR ${WORKDIR}
|
|
|
68 |
|
69 |
RUN chmod +x ${WORKDIR}/run.sh ${WORKDIR}/import-db.sh ${WORKDIR}/backup.sh
|
70 |
|
71 |
+
# 更改 postgres 用户 UID 和 GID 为 1000,设置备份目录和 crontab 目录权限
|
72 |
USER root
|
73 |
RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \
|
74 |
chown -R postgres:postgres /var/lib/postgresql /var/run/postgresql ${WORKDIR} && \
|
75 |
+
mkdir -p ${WORKDIR}/backups && chmod -R 775 ${WORKDIR}/backups && \
|
76 |
+
chmod 1730 /var/spool/cron/crontabs
|
77 |
|
78 |
# 设置定期备份任务:每4小时运行一次备份任务
|
79 |
RUN echo "0 */1 * * * /app/backup.sh" > /etc/cron.d/backup && \
|
80 |
chmod 0644 /etc/cron.d/backup && crontab /etc/cron.d/backup
|
81 |
|
|
|
82 |
# 切换到 postgres 用户
|
83 |
USER postgres
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
# 暴露 n8n 服务端口
|
86 |
EXPOSE 7860
|
87 |
|
88 |
+
# 启动 cron 服务和运行脚本
|
89 |
+
CMD service cron start && ./run.sh
|