Failed to create new OS thread (have 2 already; errno=22)
Asked Answered
A

7

60

I have mac with M1 and if i try to run docker container with nginx-proxy by jwilder, I got this error:

api_clever4sms_nginx-proxy | runtime: failed to create new OS thread (have 2 already; errno=22)
api_clever4sms_nginx-proxy | fatal error: newosproc
api_clever4sms_nginx-proxy | 
api_clever4sms_nginx-proxy | runtime stack:
api_clever4sms_nginx-proxy | runtime.throw(0x884500, 0x9)
api_clever4sms_nginx-proxy |    /usr/local/go1.6/src/runtime/panic.go:530 +0x90
api_clever4sms_nginx-proxy | runtime.newosproc(0xc820026000, 0xc820035fc0)
api_clever4sms_nginx-proxy |    /usr/local/go1.6/src/runtime/os1_linux.go:149 +0x18c
api_clever4sms_nginx-proxy | runtime.newm(0x932358, 0x0)
api_clever4sms_nginx-proxy |    /usr/local/go1.6/src/runtime/proc.go:1513 +0x135
api_clever4sms_nginx-proxy | runtime.main.func1()
api_clever4sms_nginx-proxy |    /usr/local/go1.6/src/runtime/proc.go:125 +0x2c
api_clever4sms_nginx-proxy | runtime.systemstack(0xa8e800)
api_clever4sms_nginx-proxy |    /usr/local/go1.6/src/runtime/asm_amd64.s:291 +0x79
api_clever4sms_nginx-proxy | runtime.mstart()
api_clever4sms_nginx-proxy |    /usr/local/go1.6/src/runtime/proc.go:1048
api_clever4sms_nginx-proxy | 
api_clever4sms_nginx-proxy | goroutine 1 [running]:
api_clever4sms_nginx-proxy | runtime.systemstack_switch()
api_clever4sms_nginx-proxy |    /usr/local/go1.6/src/runtime/asm_amd64.s:245 fp=0xc820020770 sp=0xc820020768
api_clever4sms_nginx-proxy | runtime.main()
api_clever4sms_nginx-proxy |    /usr/local/go1.6/src/runtime/proc.go:126 +0x62 fp=0xc8200207c0 sp=0xc820020770
api_clever4sms_nginx-proxy | runtime.goexit()
api_clever4sms_nginx-proxy |    /usr/local/go1.6/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc8200207c8 sp=0xc8200207c0
api_clever4sms_nginx-proxy exited with code 2

Please do you know how to solve this?

Apostrophe answered 24/2, 2021 at 10:53 Comment(1)
Have you tried using --platform flag ?Stalinist
K
16

You can see here that all nginx-proxy images from jwilder are built only for single platform - amd64, while your brand new mac is arm64.

What I would try to do, is to get the sources from this image's repo and build it from Dockerfile locally on your arm64 mac by yourself. This way, when you inspect your created docker image, you'll see that platform is arm64 now. And these exceptions that you posted will be gone.

When you do such things, it also always important to look up the chain of images that are base for your desired image, i.e. your image is built from nginx:1.19.3-alpine, you can see that in Dockerfile. And that image is multiplatform and supports arm64.

Keyek answered 24/3, 2021 at 9:27 Comment(0)
C
16

Docker has the ability to emulate amd64 on arm64 through qemu which is built into Docker Desktop for Mac.

Programs compiled for amd64/x86_64 should still work through this emulation if the Dockerfile is built for amd64

Dockerfile:

FROM --platform=linux/amd64 your_amd64_image
...

or env variable DOCKER_DEFAULT_PLATFORM=linux/amd64

The problem is that there seems to be a bug in qemu.

Here is a similar problem: https://gitlab.com/qemu-project/qemu/-/issues/340

Canticle answered 19/10, 2021 at 7:11 Comment(0)
T
13

In my case i needed to enable Use Rosetta for x86/amd64 emulation on Apple Silicon on my docker config under Features in development.

enter image description here

Tades answered 2/10, 2023 at 11:32 Comment(2)
I had some older project with SB 1.5 and some older TestContainers images, this was the solution that worked for me. My Error was 09:58:38.927 [main] ERROR 🐳 [mysql:5.6.43] - Log output from the failed container: runtime: failed to create new OS thread (have 2 already; errno=22) fatal error: newosproc runtime stack: runtime.throw(0x524da0, 0x9)Salesman
Lifesaver!!. I updated Docker desktop and forgot to change this, i couldnñt run nginx on my mac m1. Tried just about everything, this is the only thing that worked.Pyrolysis
P
12

For anyone else who has an error similar to this but with a different container, the tip above by @RomanShamborovskyi about checking which images are available on DockerHub is what solved the issue for me. In my case, my docker-compose.yml file was configured to use image: redis:3.2.4 which was only listed with support for linux/amd64, however, I was able to upgrade to image: redis: 3.2.10 which was listed with support for linux/arm/v7 and that worked for me within Docker without encountering an error. If you can find a similar version of your software with arm support that only requires a small patch update then hopefully it won't require refactoring your code like updating to a higher major version number would.

Parapet answered 28/1, 2022 at 0:10 Comment(1)
I was having an issue with redis:3.2.4 as well! This resolved my problem. Thanks, Allen!Marden
L
8

I run mysql docker in my M1 (arm64) and I got the same error when I try to build a container. I change mysql docker image to be image: mysql:8.0.26, platform: linux/x86_64 and add default_authentication_plugin=mysql_native_password to my.cnf Then I rebuild a docker container through those settings and it works.

Lynnette answered 9/11, 2021 at 22:7 Comment(1)
Thanks, we had an old docker-compose.yml that was using mysql:8.0.16 and updating to mysql:8.0.26, platform: linux/amd64 allowed MySQL to successfully startup on an M1 Mac.Vying
D
7

I had the same issue with the in-house docker container, I've checked the docker docs and this has helped me: https://collabnix.com/warning-the-requested-images-platform-linux-amd64-does-not-match-the-detected-host-platform-linux-arm64-v8/ .

TLDR:

  1. Go to the Settings > section and check the box to enable the Apple Virtualization framework.
  2. Under the “Feature in development section”, enable Rosetta.
Dagny answered 20/7, 2023 at 9:56 Comment(0)
S
-1

Add platform: linux/arm64 and if you're using mysql use image: mysql:5.7

Sulphanilamide answered 8/5, 2024 at 13:7 Comment(1)
Please add some explanation to your answer such that others can learn from it. MySQL 5.7 is EOL since 2023Pyrargyrite

© 2022 - 2025 — McMap. All rights reserved.