I am using docker and gunicorn for my python application. I am starting gunicorn as below:
CMD ["gunicorn", "--workers 2", "--threads 2", "--bind 0.0.0.0:8000", "--preload", ""main:create_app()""]
But getting error as wrong syntax, because of last element i.e. (""main:create_app()""). As given in gunicorn documentation, I am trying to use below form:
def create_app():
app = FrameworkApp()
...
return app
$ gunicorn --workers=2 'test:create_app()'
I Also tried single quotes as "'main:create_app()'", But this also failed.
What I am missing?
Correct usage is:
RUN ["gunicorn", "--workers", "2", "--threads", "2", "--bind", "0.0.0.0:8000", "--preload", "main:create_app()"]
--workers
and 2
are two different strings, instead of being one string --workers 2
; the same goes for everywhere else you have an argument and an argument-option paired.'main:create_app()'
, are instructions to the shell that symbols like ()
should not be treated as shell syntax. Because there is no shell here, those instructions are unnecessary. Just use "main:create_app()"
as a simple JSON string, with only JSON quotes; no literal quotes are necessary or appropriate.If you have questions in the future about how to convert a simple command to a JSON string, you can ask jq
to do it for you:
$ jq -cn --args '$ARGS.positional' -- gunicorn --workers 2 --threads 2 --bind 0.0.0.0:8000 --preload 'main:create_app()'
["gunicorn","--workers","2","--threads","2","--bind","0.0.0.0:8000","--preload","main:create_app()"]