M1 Mac执行docker-compose run报错:无法创建新OS线程
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/amd64to your Dockerfile, but you also need to enforce this at the compose level to ensure every service uses the correct emulation context. Update yourdocker-compose.yml:services: your-service-name: build: . platform: linux/amd64 # Keep your other service configs hereReset 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 amd64Increase Container Thread Limits
The error explicitly mentions hitting a thread count cap. Add ulimit settings to your service indocker-compose.ymlto raise the limits:services: your-service-name: # Other configs ulimits: nproc: 65535 nofile: soft: 65535 hard: 65535Use 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

