Update Dockerfile
Browse files- Dockerfile +46 -34
Dockerfile
CHANGED
@@ -1,36 +1,48 @@
|
|
1 |
-
#
|
2 |
-
FROM
|
3 |
-
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
#
|
14 |
-
RUN
|
15 |
-
&&
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
RUN git clone https://github.com/electerm/electerm.git
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
EXPOSE 7860
|
34 |
|
35 |
-
#
|
36 |
-
CMD ["
|
|
|
1 |
+
# 使用基于 Ubuntu 的官方 Node.js 20 镜像
|
2 |
+
FROM node:20
|
3 |
+
|
4 |
+
# 定义构建时间参数
|
5 |
+
ARG BUILD_DATE
|
6 |
+
LABEL build-date=$BUILD_DATE
|
7 |
+
LABEL maintainer="ZHAO Xudong <zxdong@gmail.com>"
|
8 |
+
LABEL description="This is Docker image for electerm-web"
|
9 |
+
LABEL url="https://github.com/electerm/electerm-web-docker"
|
10 |
+
LABEL vendor="electerm"
|
11 |
+
LABEL version="2.39.109"
|
12 |
+
|
13 |
+
# 安装构建工具,创建用户并设置权限
|
14 |
+
RUN apt-get update && apt-get install -y git make build-essential g++ \
|
15 |
+
&& groupadd -r electerm && useradd -r -g electerm -d /home/electerm -s /bin/bash electerm \
|
16 |
+
&& mkdir /home/electerm && chown -R electerm:electerm /home/electerm && chmod 755 /home/electerm
|
17 |
+
|
18 |
+
# 设置工作目录并确保权限正确
|
19 |
+
USER electerm
|
20 |
+
WORKDIR /app
|
21 |
+
RUN git clone --depth 1 https://github.com/electerm/electerm-web.git
|
22 |
+
|
23 |
+
WORKDIR /app/electerm-web
|
24 |
+
|
25 |
+
# 安装依赖并构建项目
|
26 |
+
RUN npm uninstall @playwright/test chai playwright \
|
27 |
+
&& npm install --production \
|
28 |
+
&& npm run build \
|
29 |
+
&& cp .sample.env .env \
|
30 |
+
&& npm cache clean --force
|
31 |
+
|
32 |
+
# 切换回 root 用户以删除不再需要的包,并清理系统
|
33 |
+
USER root
|
34 |
+
RUN apt-get remove -y git make build-essential g++ \
|
35 |
+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
36 |
+
|
37 |
+
# 切换回 electerm 用户继续运行应用
|
38 |
+
USER electerm
|
39 |
+
WORKDIR /app/electerm-web
|
40 |
+
|
41 |
+
# 设置环境变量
|
42 |
+
ENV NODE_ENV=production
|
43 |
+
|
44 |
+
# 暴露必要的端口 (根据项目需求)
|
45 |
EXPOSE 7860
|
46 |
|
47 |
+
# 运行应用
|
48 |
+
CMD ["node", "./src/app/app.js"]
|