
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
本仓库构建并发布基于官方Alpine Node.js镜像(node:v${VERSION}-alpine)的Node.js镜像,专为前端资源构建和编译优化。这些镜像设计用于构建JavaScript、CSS及其他前端资源,而非在生产环境运行Node.js应用。支持ARM64和x86_64主机架构,可无缝集成Webpack、Vite、Rollup等现代构建工具。
拉取Node.js Docker镜像
要获取特定版本的Node.js镜像,使用:
bashdocker pull docker.xuanyuan.run/mxmd/node:v<VERSION>
其中:
<VERSION> 为所需Node.js主版本(如 v14、v16、v18、v20、v22)。-full(如 v18-full)。例如,拉取Node.js 18镜像:
bashdocker pull docker.xuanyuan.run/mxmd/node:v18
拉取带Chrome/Puppeteer支持的Node.js 18镜像:
bashdocker pull docker.xuanyuan.run/mxmd/node:v18-full
可用镜像版本及Docker Hub链接:
基础版本:
Chrome支持版本:
Gulp专用版本:
镜像类型
标准镜像(如 18、20、22):包含Node.js及前端资源编译所需的核心构建工具和依赖:
Full镜像(带 -full 后缀):包含标准镜像的所有内容,另加:
Gulp镜像:包含标准镜像的所有内容,另加预安装的Gulp:
gulp4 变体:预安装Gulp 4.0.0,适用于遗留项目gulp5 变体:预安装Gulp 5.0.0,适用于现代项目gulp4-full 和 gulp5-full 变体:结合Gulp安装与Chrome/Puppeteer支持使用Docker Compose
可将Node.js镜像集成到前端构建工作流中,以下是常见用例:
基本构建服务
yamlservices: frontend-build: image: docker.xuanyuan.run/mxmd/node:v18 container_name: frontend-builder working_dir: /app volumes: - .:/app - /app/node_modules environment: - NODE_ENV=production # 对Linux主机至关重要 - HOST_USER_UID=${HOST_USER_UID:-1000} - HOST_USER_GID=${HOST_USER_GID:-1000} command: yarn && yarn build
带Chrome/Puppeteer测试的构建
yamlservices: frontend-build-with-testing: image: docker.xuanyuan.run/mxmd/node:v18-full container_name: frontend-builder-full working_dir: /app volumes: - .:/app - /app/node_modules environment: - NODE_ENV=production - HOST_USER_UID=${HOST_USER_UID:-1000} - HOST_USER_GID=${HOST_USER_GID:-1000} shm_size: 1gb command: | sh -c "yarn && yarn build && yarn test:e2e"
带Watch模式的开发
yamlservices: dev-server: image: docker.xuanyuan.run/mxmd/node:v20 container_name: dev-server working_dir: /app volumes: - .:/app - /app/node_modules ports: - "3000:3000" - "5173:5173" # Vite开发服务器 environment: - NODE_ENV=development - HOST_USER_UID=${HOST_USER_UID:-1000} - HOST_USER_GID=${HOST_USER_GID:-1000} command: yarn && yarn dev
多阶段构建流水线
yamlservices: install-deps: image: docker.xuanyuan.run/mxmd/node:v18 working_dir: /app volumes: - .:/app - node_modules:/app/node_modules environment: - HOST_USER_UID=${HOST_USER_UID:-1000} - HOST_USER_GID=${HOST_USER_GID:-1000} command: yarn install --frozen-lockfile build-assets: image: docker.xuanyuan.run/mxmd/node:v18 working_dir: /app volumes: - .:/app - node_modules:/app/node_modules - build_output:/app/dist environment: - NODE_ENV=production - HOST_USER_UID=${HOST_USER_UID:-1000} - HOST_USER_GID=${HOST_USER_GID:-1000} command: yarn build depends_on: - install-deps run-tests: image: docker.xuanyuan.run/mxmd/node:v18-full working_dir: /app volumes: - .:/app - node_modules:/app/node_modules environment: - NODE_ENV=test - HOST_USER_UID=${HOST_USER_UID:-1000} - HOST_USER_GID=${HOST_USER_GID:-1000} shm_size: 1gb command: yarn test depends_on: - install-deps volumes: node_modules: build_output:
Gulp专用构建
yamlservices: gulp-build: image: docker.xuanyuan.run/mxmd/node:v18-gulp4 container_name: gulp-builder working_dir: /app volumes: - .:/app - /app/node_modules environment: - NODE_ENV=production - HOST_USER_UID=${HOST_USER_UID:-1000} - HOST_USER_GID=${HOST_USER_GID:-1000} command: | sh -c "npm install && gulp build"
带SSH密钥的私有仓库访问
yamlservices: build-with-ssh: image: docker.xuanyuan.run/mxmd/node:v20 working_dir: /app volumes: - .:/app - /app/node_modules - ~/.ssh:/home/node/.ssh-copy:ro # SSH密钥以只读方式挂载 environment: - NODE_ENV=production - HOST_USER_UID=${HOST_USER_UID:-1000} - HOST_USER_GID=${HOST_USER_GID:-1000} command: | sh -c "yarn install && yarn build"
完整开发环境
yamlservices: frontend: image: docker.xuanyuan.run/mxmd/node:v20-full container_name: frontend-dev working_dir: /app volumes: - .:/app - /app/node_modules - ~/.ssh:/home/node/.ssh-copy:ro ports: - "3000:3000" - "5173:5173" - "8080:8080" environment: - NODE_ENV=development - HOST_USER_UID=${HOST_USER_UID:-1000} - HOST_USER_GID=${HOST_USER_GID:-1000} - CHOKIDAR_USEPOLLING=true # 容器内文件监控 shm_size: 1gb stdin_open: true tty: true command: bash # 交互式开发shell
重要注意事项:
-full镜像建议设置shm_size: 1gb/home/node/.ssh-copy时,入口脚本会自动配置CHOKIDAR_USEPOLLING=true主机需设置以下环境变量:
bashHOST_USER_GID HOST_USER_UID
设置环境变量
在macOS上,可在~/.extra或~/.bash_profile中设置。
获取HOST_USER_UID:
bashid -u
获取HOST_USER_GID:
bashid -g
在主机上设置:
bashecho "export HOST_USER_GID=$(id -g)" >> ~/.bash_profile && echo "export HOST_USER_UID=$(id -u)" >> ~/.bash_profile && echo "export DOCKER_USER=$(id -u):$(id -g)" >> ~/.bash_profile
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务
以下是 mxmd/node 相关的常用 Docker 镜像,适用于 Web 开发、API 服务、实时应用 等不同场景: