AlanSTACK
AlanSTACK

Reputation: 6075

Pull number of cores dynamically in Dockerfile

Currently I am packaging a web application with Docker, and one line in my Dockerfile is the following

CMD gunicorn -w 4 -b 0.0.0.0:80 main:app

I was wondering if its possible to change -w 4 to something like -w $(num_cores) * 2 + 1

How would I go about doing this?

Upvotes: 3

Views: 543

Answers (1)

prithajnath
prithajnath

Reputation: 2115

If you're in Linux, you can use the nproc command

CMD gunicorn -w $(expr $(nproc) \* 2 + 1) -b 0.0.0.0:80 main:app

Upvotes: 4

Related Questions