forked from microsoft/SceneLandmarkLocalization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
81 lines (61 loc) · 2.19 KB
/
Dockerfile
File metadata and controls
81 lines (61 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
FROM pytorch/pytorch:2.7.1-cuda12.6-cudnn9-runtime AS base_build
ENV TZ=Asia/Shanghai
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
# 设置时区和镜像源
RUN ln -fs /usr/share/zoneinfo/$TZ /etc/localtime
RUN sed -i \
-e 's|http://archive.ubuntu.com|https://mirrors.ustc.edu.cn/ubuntu|g' \
-e 's|http://security.ubuntu.com|https://mirrors.ustc.edu.cn/ubuntu|g' \
/etc/apt/sources.list
RUN apt-get update && apt-get install -y sudo ca-certificates
RUN sudo update-ca-certificates --fresh
# 设置工作目录
WORKDIR /app
# 安装系统依赖
RUN apt-get install -y \
git wget curl unzip \
libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender-dev libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# 复制requirements.txt文件
COPY src/requirements.txt .
# 安装Python依赖
RUN pip install -r requirements.txt -i https://repo.huaweicloud.com/repository/pypi/simple/
# 创建目录和用户
RUN mkdir -p /app/logs && \
useradd -m -u 1000 appuser && \
chown -R appuser:appuser /app
# 主服务阶段
FROM base_build AS main
CMD ["python", "/app/src/main.py", "--help"]
# API服务阶段
FROM base_build AS api
# 设置API环境变量
ENV FLASK_ENV=production
ENV FLASK_APP=src/api_server.py
# 安装API服务依赖
RUN apt-get update && apt-get install -y nginx supervisor && \
rm -rf /var/lib/apt/lists/* && \
pip install gunicorn -i https://repo.huaweicloud.com/repository/pypi/simple/
# 创建日志目录
RUN mkdir -p /var/log/api && chown -R appuser:appuser /var/log/api
# 创建supervisor配置目录
RUN mkdir -p /etc/supervisor/conf.d
# 复制supervisor配置文件
COPY supervisor.conf /etc/supervisor/conf.d/api.conf
RUN ls -la /etc/supervisor/conf.d/api.conf
# 复制nginx配置文件
COPY nginx.conf /etc/nginx/sites-available/api
RUN ls -la /etc/nginx/sites-available/api
# 启用nginx配置
RUN ln -s /etc/nginx/sites-available/api /etc/nginx/sites-enabled/ && \
rm /etc/nginx/sites-enabled/default
# 复制启动脚本
COPY start_api.sh /app/start_api.sh
RUN chmod +x /app/start_api.sh && \
ls -la /app/start_api.sh && \
cat /app/start_api.sh
# 暴露端口
EXPOSE 80 8080
# 设置默认命令(以root用户运行supervisor)
CMD ["/app/start_api.sh"]