node-red/Dockerfile
2025-08-28 16:20:24 +08:00

30 lines
901 B
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 1. 使用官方 Node.js 20-alpine 镜像作为基础
FROM node:20-alpine
# 2. 在容器中创建并设置工作目录
WORKDIR /usr/src/app
# 3. 复制 package.json 和 package-lock.json (如果存在)
# 这样可以利用 Docker 的层缓存机制,只有在依赖更新时才重新安装
COPY package*.json ./
# 4. 安装所有依赖(包括构建所需的 devDependencies
RUN npm install
# 5. 复制项目的所有源代码到工作目录
COPY . .
# 6. 运行构建脚本,生成生产环境的前端资源
RUN npm run build
# 7. 创建一个挂载点用于持久化 Node-RED 的用户数据(流程、凭证等)
# 官方推荐的目录是 /data
VOLUME /data
# 8. 暴露 Node-RED 运行的端口
EXPOSE 1880
# 9. 定义容器启动时运行的命令
# 使用 --userDir /data 来告诉 Node-RED 在哪里存储用户数据
CMD [ "npm", "run", "start", "--", "--userDir", "/data" ]