How can I insert nproc
in Dockerfile inside a CMD
instruction in the exec
format?
I have this:
CMD [ "gunicorn", \
"--access-logfile", "-", \
"--error-logfile", "-", \
"--bind=\"0.0.0.0:${PORT}\"", \
"--workers=$(( $(nproc) * 2 + 1))", \
"--worker-class=\"uvicorn.workers.UvicornWorker\"", \
"--log-level=\"${LOGLEVEL}\"", \
"\"app:app\"" ]
but I'm getting this error:
usage: gunicorn [OPTIONS] [APP_MODULE]
gunicorn: error: argument -w/--workers: invalid int value: '$(( $(nproc) * 2 + 1))'
Thanks
UPDATE:
After reading the @david-maze commentary, I searched and I solved creating a entrypoint.sh
with this:
#!/bin/sh
set -e
exec gunicorn \
--access-logfile - \
--error-logfile - \
--bind="0.0.0.0:${PORT}" \
--workers=$(( $(nproc) * 2 + 1)) \
--threads=2 \
--worker-class="uvicorn.workers.UvicornWorker" \
--log-level="${LOGLEVEL}" \
"app:app" \
"$@"
And my Dockerfile
ends with:
# (...)
WORKDIR sfhskjd
# ENTRYPOINT ["./entrypoint.sh"]
CMD ["./entrypoint.sh"]
It's working as I want