Pull number of cores dynamically in Dockerfile

Viewed 69

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?

1 Answers

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
Related