You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker部署Node.js项目报错non-zero code:134的解决求助

问题:Docker构建Node项目时出现线程创建断言失败错误

环境与配置

Dockerfile

FROM node:lts AS runtime
WORKDIR /app

COPY . .

RUN npm install --verbose
RUN npm run build

ENV HOST=0.0.0.0
ENV PORT=3000
EXPOSE 3000
CMD node ./dist/server/entry.mjs

docker-compose.yml

version: '3'
services:
  xxxxxx:
    build: .
    ports:
      - "3000:3000"

问题现象

项目在本地Mac环境运行正常,但部署到Ubuntu服务器执行sudo docker-compose up时,构建阶段报错:

#  node[7]: std::unique_ptr<long unsigned int> node::WorkerThreadsTaskRunner::DelayedTaskScheduler::Start() at ../src/node_platform.cc:68
  #  Assertion failed: (0) == (uv_thread_create(t.get(), start_thread, this))

----- Native stack trace -----

 1: 0xe2fcd7 node::Assert(node::AssertionInfo const&) [node]
 2: 0xeb54ce node::WorkerThreadsTaskRunner::WorkerThreadsTaskRunner(int) [node]
 3: 0xeb55ac node::NodePlatform::NodePlatform(int, v8::TracingController*, v8::PageAllocator*) [node]
 4: 0xdd22b6  [node]
 5: 0xdd37b4 node::Start(int, char**) [node]
 6: 0x7f513d15624a  [/lib/x86_64-linux-gnu/libc.so.6]
 7: 0x7f513d156305 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
 8: 0xd2717e _start [node]
Aborted (core dumped)
ERROR: Service 'xxxxxx' failed to build: The command '/bin/sh -c npm install --verbose' returned a non-zero code: 134

已尝试操作

怀疑是Node版本问题,将Dockerfile改为FROM node:21.7后问题依旧;本地构建镜像推送到服务器运行,仍出现类似错误:

#  node[8]: std::unique_ptr<long unsigned int> node::WorkerThreadsTaskRunner::DelayedTaskScheduler::Start() at ../src/node_platform.cc:68


  #  Assertion failed: (0) == (uv_thread_create(t.get(), start_thread, this))



----- Native stack trace -----



 1: 0xcba0f7 node::Assert(node::AssertionInfo const&) [node]


 2: 0xd3942e node::WorkerThreadsTaskRunner::WorkerThreadsTaskRunner(int) [node]


 3: 0xd3950c node::NodePlatform::NodePlatform(int, v8::TracingController*, v8::PageAllocator*) [node]


 4: 0xc6e2d6  [node]


 5: 0xc6f7d4 node::Start(int, char**) [node]


 6: 0x7f4ef3aad24a  [/lib/x86_64-linux-gnu/libc.so.6]


 7: 0x7f4ef3aad305 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]


 8: 0xbc5c8e _start [node]


Aborted (core dumped)

原因分析

这个错误是Node底层的libuv库在创建工作线程时失败,触发了断言检查。常见诱因包括:

  • 服务器线程数限制:Ubuntu服务器对用户进程的可用线程数做了严格限制,导致uv_thread_create返回非0值
  • 服务器资源不足:内存不足时,系统无法为新线程分配所需资源
  • Docker容器资源配额不足:容器默认的线程数、文件句柄等配额不足以支撑Node的线程创建需求

解决方法

1. 调整服务器线程数限制

  • 查看当前用户线程数上限:执行 ulimit -u
  • 临时调整上限:执行 ulimit -u 4096(数值可根据服务器配置调整)
  • 永久生效:编辑/etc/security/limits.conf,添加以下内容后重启服务器或重新登录:
    * soft nproc 4096
    * hard nproc 4096
    

2. 给Docker容器增加资源限制

修改docker-compose.yml,添加ulimits配置放宽资源配额:

version: '3'
services:
  xxxxxx:
    build: .
    ports:
      - "3000:3000"
    ulimits:
      nproc: 4096
      nofile:
        soft: 65536
        hard: 65536

3. 禁用Node的工作线程

修改Dockerfile中的命令,强制禁用工作线程:

RUN npm install --verbose --no-worker-threads
RUN npm run build --no-worker-threads
CMD node --no-worker-threads ./dist/server/entry.mjs

4. 检查服务器内存资源

执行free -h查看内存使用情况,若内存不足,可考虑增加服务器内存或关闭其他占用资源的进程

内容的提问来源于stack exchange,提问作者sooon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 11:17:35