Update Dockerfile
Browse files- Dockerfile +14 -2
Dockerfile
CHANGED
@@ -16,8 +16,7 @@ RUN apt-get update && apt-get install -y \
|
|
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/*
|
@@ -29,6 +28,19 @@ RUN usermod -u 1000 postgres && groupmod -g 1000 postgres
|
|
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 && \
|
|
|
16 |
python3 \
|
17 |
python3-pip \
|
18 |
python3-venv \
|
19 |
+
curl gosu \
|
|
|
20 |
--no-install-recommends && \
|
21 |
apt-get clean && \
|
22 |
rm -rf /var/lib/apt/lists/*
|
|
|
28 |
RUN chown -R postgres:postgres /var/lib/postgresql && \
|
29 |
chown -R postgres:postgres /var/run/postgresql
|
30 |
|
31 |
+
# 切换到 postgres 用户,初始化数据库并创建角色
|
32 |
+
USER postgres
|
33 |
+
|
34 |
+
# 初始化 PostgreSQL 数据库,并创建指定的用户角色和数据库
|
35 |
+
RUN initdb -D /var/lib/postgresql/data && \
|
36 |
+
pg_ctl start -D /var/lib/postgresql/data && \
|
37 |
+
psql --command "CREATE ROLE $POSTGRES_USER WITH LOGIN SUPERUSER PASSWORD '$POSTGRES_PASSWORD';" && \
|
38 |
+
createdb -O $POSTGRES_USER $POSTGRES_DB && \
|
39 |
+
pg_ctl stop -D /var/lib/postgresql/data
|
40 |
+
|
41 |
+
# 切换回 root 用户以安装 Python 依赖
|
42 |
+
USER root
|
43 |
+
|
44 |
# 创建虚拟环境并安装 Python 包
|
45 |
RUN python3 -m venv $VIRTUAL_ENV && \
|
46 |
$VIRTUAL_ENV/bin/pip install --upgrade pip && \
|