Q&A: "RuntimeError: can't start new thread" in a docker container

Question

When I try to install dependencies via pip inside a container (or do something else that initializes a new thread) the error RuntimeError: can't start new thread is thrown.

To reproduce:

from threading import Thread
def threaded_print(arg):
    print(arg)
thread = Thread(target=threaded_print, args=("Hello World",))
thread.start() 

Answer

The container is missing a security option. For a docker-compose setup you need to append the following:

security_opt:
      - seccomp:/etc/docker/seccomp-systemd.json

If you use docker directly you can solve this via:

docker run --security-opt seccomp=/path/to/seccomp/profile.json <image>
Mastodon