Update Dockerfile
Browse files- Dockerfile +14 -7
Dockerfile
CHANGED
@@ -1,24 +1,28 @@
|
|
1 |
-
# 使用 PostgreSQL
|
2 |
FROM postgres:latest
|
3 |
|
4 |
-
#
|
5 |
ENV POSTGRES_USER=myuser \
|
6 |
POSTGRES_PASSWORD=mypassword \
|
7 |
POSTGRES_DB=mydatabase \
|
8 |
VIRTUAL_ENV=/opt/venv \
|
9 |
PATH="$VIRTUAL_ENV/bin:$PATH"
|
10 |
|
11 |
-
#
|
|
|
|
|
|
|
12 |
RUN apt-get update && apt-get install -y \
|
13 |
python3 \
|
14 |
python3-pip \
|
15 |
python3-venv \
|
|
|
16 |
curl \
|
17 |
--no-install-recommends && \
|
18 |
apt-get clean && \
|
19 |
rm -rf /var/lib/apt/lists/*
|
20 |
|
21 |
-
#
|
22 |
RUN python3 -m venv $VIRTUAL_ENV && \
|
23 |
$VIRTUAL_ENV/bin/pip install --upgrade pip && \
|
24 |
$VIRTUAL_ENV/bin/pip install Flask psycopg2-binary
|
@@ -27,15 +31,18 @@ RUN python3 -m venv $VIRTUAL_ENV && \
|
|
27 |
COPY app.py /app/app.py
|
28 |
COPY run.sh /app/run.sh
|
29 |
|
30 |
-
#
|
31 |
RUN chmod +x /app/run.sh
|
32 |
|
|
|
|
|
|
|
33 |
# 设置工作目录
|
34 |
WORKDIR /app
|
35 |
|
36 |
# 启动容器时执行run.sh脚本
|
37 |
CMD ["./run.sh"]
|
38 |
|
39 |
-
#
|
40 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
|
41 |
-
CMD curl -f http://localhost:7860/ || exit 1
|
|
|
1 |
+
# 使用 PostgreSQL 官方镜像
|
2 |
FROM postgres:latest
|
3 |
|
4 |
+
# 设置环境变量,用于数据库配置
|
5 |
ENV POSTGRES_USER=myuser \
|
6 |
POSTGRES_PASSWORD=mypassword \
|
7 |
POSTGRES_DB=mydatabase \
|
8 |
VIRTUAL_ENV=/opt/venv \
|
9 |
PATH="$VIRTUAL_ENV/bin:$PATH"
|
10 |
|
11 |
+
# 切换到 root 用户进行安装
|
12 |
+
USER root
|
13 |
+
|
14 |
+
# 更新包管理器并安装必要软件包,包括 Python3、venv 和 curl
|
15 |
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 && \
|
28 |
$VIRTUAL_ENV/bin/pip install Flask psycopg2-binary
|
|
|
31 |
COPY app.py /app/app.py
|
32 |
COPY run.sh /app/run.sh
|
33 |
|
34 |
+
# 设置脚本可执行权限
|
35 |
RUN chmod +x /app/run.sh
|
36 |
|
37 |
+
# 切换到 postgres 用户以确保 PostgreSQL 服务正常运行
|
38 |
+
USER postgres
|
39 |
+
|
40 |
# 设置工作目录
|
41 |
WORKDIR /app
|
42 |
|
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
|