aigenai commited on
Commit
7f49ed9
·
verified ·
1 Parent(s): de52305

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +12 -5
Dockerfile CHANGED
@@ -8,7 +8,7 @@ ENV POSTGRES_USER=myuser \
8
  VIRTUAL_ENV=/opt/venv \
9
  PATH="$VIRTUAL_ENV/bin:$PATH"
10
 
11
- # 切换到 root 用户进行安装
12
  USER root
13
 
14
  # 更新包管理器并安装必要软件包,包括 Python3、venv 和 curl
@@ -16,12 +16,19 @@ RUN apt-get update && apt-get install -y \
16
  python3 \
17
  python3-pip \
18
  python3-venv \
19
- gosu \
20
  curl \
 
21
  --no-install-recommends && \
22
  apt-get clean && \
23
  rm -rf /var/lib/apt/lists/*
24
 
 
 
 
 
 
 
 
25
  # 创建虚拟环境并安装 Python 包
26
  RUN python3 -m venv $VIRTUAL_ENV && \
27
  $VIRTUAL_ENV/bin/pip install --upgrade pip && \
@@ -34,7 +41,7 @@ COPY run.sh /app/run.sh
34
  # 设置脚本可执行权限
35
  RUN chmod +x /app/run.sh
36
 
37
- # 切换到 postgres 用户以确保 PostgreSQL 服务正常运行
38
  USER postgres
39
 
40
  # 设置工作目录
@@ -43,6 +50,6 @@ WORKDIR /app
43
  # 启动容器时执行run.sh脚本
44
  CMD ["./run.sh"]
45
 
46
- # 设置健康检查以确保Flask应用正常运行
47
  HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
48
- CMD curl -f http://localhost:7860/ || exit 1
 
8
  VIRTUAL_ENV=/opt/venv \
9
  PATH="$VIRTUAL_ENV/bin:$PATH"
10
 
11
+ # 切换到 root 用户进行安装和用户修改
12
  USER root
13
 
14
  # 更新包管理器并安装必要软件包,包括 Python3、venv 和 curl
 
16
  python3 \
17
  python3-pip \
18
  python3-venv \
 
19
  curl \
20
+ gosu \
21
  --no-install-recommends && \
22
  apt-get clean && \
23
  rm -rf /var/lib/apt/lists/*
24
 
25
+ # 更改现有的 postgres 用户 UID 和 GID 为 1000
26
+ RUN usermod -u 1000 postgres && groupmod -g 1000 postgres
27
+
28
+ # 修正数据库目录的所有者和组,确保新 UID 和 GID 能正常访问
29
+ RUN chown -R postgres:postgres /var/lib/postgresql && \
30
+ chown -R postgres:postgres /var/run/postgresql
31
+
32
  # 创建虚拟环境并安装 Python 包
33
  RUN python3 -m venv $VIRTUAL_ENV && \
34
  $VIRTUAL_ENV/bin/pip install --upgrade pip && \
 
41
  # 设置脚本可执行权限
42
  RUN chmod +x /app/run.sh
43
 
44
+ # 切换到更改后的 postgres 用户
45
  USER postgres
46
 
47
  # 设置工作目录
 
50
  # 启动容器时执行run.sh脚本
51
  CMD ["./run.sh"]
52
 
53
+ # 设置健康检查以确保 Flask 应用正常运行
54
  HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
55
+ CMD curl -f http://localhost:7860/ || exit 1