Created
September 30, 2022 01:06
-
-
Save miohtama/188a8d3e53a18db1640d82a2099a551a to your computer and use it in GitHub Desktop.
How to launch gunicorn inside Docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Start backend using Gunicorn web server. | |
# | |
# - Run as a standalone UNIX daemon | |
# - Run inside a Docker container | |
# - Read config file for more settings that cannot be given on command line | |
# | |
# See https://docs.gunicorn.org/en/stable/settings.html | |
# | |
# https://stackoverflow.com/a/25518345/315168 | |
if [ -f /.dockerenv ]; then | |
# Launched within Docker | |
echo "Launching as a Docker container" | |
LISTEN=0.0.0.0:3456 | |
else | |
echo "Launching as a UNIX daemon" | |
# Launched standalone, | |
# assume prod server | |
LISTEN=127.0.0.1:3456 | |
fi | |
gunicorn \ | |
--name backend \ | |
--config=gunicorn-config.py \ | |
--bind $LISTEN \ | |
--preload \ | |
--workers 16 \ | |
--threads 2 \ | |
--timeout 30 \ | |
--max-requests 500 \ | |
--env "SCRIPT_NAME=/api" \ | |
--access-logfile logs/gunicorn_access.log \ | |
--error-logfile logs/gunicorn_error.log \ | |
"backend.server.server:gunicorn_entry_point()" | |
echo "gunicorn exited, exit code $?" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment