ScopeSentry/dockerfile

45 lines
1.3 KiB
Plaintext
Raw Normal View History

2024-06-12 11:15:20 +00:00
FROM python:3.7-slim
2024-06-05 13:39:34 +00:00
2024-06-12 11:15:20 +00:00
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
2024-06-12 12:40:02 +00:00
# 更新包列表并安装必要的包,包括 nginx
2024-06-05 13:39:34 +00:00
RUN apt-get update && \
2024-06-12 12:40:02 +00:00
apt-get install -y git curl ca-certificates libcurl4-openssl-dev nginx && \
2024-06-05 13:39:34 +00:00
apt-get clean && \
rm -rf /var/lib/apt/lists/*
2024-06-12 12:40:02 +00:00
# 设置工作目录
2024-06-05 13:39:34 +00:00
WORKDIR /opt/ScopeSentry/
2024-06-12 12:40:02 +00:00
# 复制 ScopeSentry 项目文件到工作目录
2024-06-05 13:39:34 +00:00
COPY ./ScopeSentry /opt/ScopeSentry/
2024-06-12 12:40:02 +00:00
# 安装 Python 依赖包
2024-06-05 13:39:34 +00:00
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir
2024-06-12 12:40:02 +00:00
# 修改 Nginx 配置文件,添加反向代理规则
RUN echo 'server {\n\
listen 80;\n\
server_name localhost;\n\
\n\
location / {\n\
2024-06-17 14:42:28 +00:00
root /opt/ScopeSentry/static;\n\
2024-06-12 12:40:02 +00:00
try_files $uri $uri/ =404;\n\
}\n\
\n\
location /api/ {\n\
proxy_pass http://127.0.0.1:8082;\n\
proxy_set_header Host $host;\n\
proxy_set_header X-Real-IP $remote_addr;\n\
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
proxy_set_header X-Forwarded-Proto $scheme;\n\
}\n\
}\n' > /etc/nginx/sites-available/default
# 确保 Nginx 默认配置启用
RUN ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/
# 启动 Nginx 和 Python 应用
CMD service nginx start && python main.py