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

M1 Mac执行docker-compose run报错:无法创建新OS线程

Fixing "runtime: failed to create new OS thread" Error on M1 Mac with Docker Compose

I’ve run into this exact thread-limiting issue on my M1 Mac when running AMD64 containers, so I know how frustrating it can be. The error happens because the QEMU emulation layer (used to run x86/amd64 images on ARM) has strict thread limits by default, and your existing fixes only covered part of the problem. Let’s walk through the targeted fixes that should resolve this:

  • Bump Docker Desktop Resource Allocation
    By default, Docker Desktop on M1 allocates minimal CPU and memory to emulated containers, which can trigger thread creation failures. Go to Docker Desktop > Settings > Resources > Advanced, set CPU to at least 4 cores and Memory to 8GB (or higher if you can), then restart Docker. This gives the emulation layer enough headroom to spawn threads.

  • Add Platform Configuration to docker-compose.yml
    You added --platform=linux/amd64 to your Dockerfile, but you also need to enforce this at the compose level to ensure every service uses the correct emulation context. Update your docker-compose.yml:

    services:
      your-service-name:
        build: .
        platform: linux/amd64
        # Keep your other service configs here
    
  • Reset QEMU Binfmt Configuration
    Sometimes the QEMU emulation state gets corrupted. Run these commands to reset it, then restart Docker Desktop:

    docker run --privileged --rm tonistiigi/binfmt --uninstall all
    docker run --privileged --rm tonistiigi/binfmt --install amd64
    
  • Increase Container Thread Limits
    The error explicitly mentions hitting a thread count cap. Add ulimit settings to your service in docker-compose.yml to raise the limits:

    services:
      your-service-name:
        # Other configs
        ulimits:
          nproc: 65535
          nofile:
            soft: 65535
            hard: 65535
    
  • Use Rosetta for Emulation (Recommended)
    Docker Desktop has a Rosetta integration that’s far more efficient than QEMU for x86/amd64 containers on M1. Enable it by going to Docker Desktop > Settings > Features in Development, check "Use Rosetta for x86/amd64 emulation on Apple Silicon", then restart Docker. This drastically reduces thread-related bottlenecks.

Try these steps in order—most likely the combination of resource allocation and Rosetta emulation will fix the issue right away.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 18:10:30