Skip to content

Instantly share code, notes, and snippets.

@miohtama
Created September 30, 2022 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miohtama/188a8d3e53a18db1640d82a2099a551a to your computer and use it in GitHub Desktop.
Save miohtama/188a8d3e53a18db1640d82a2099a551a to your computer and use it in GitHub Desktop.
How to launch gunicorn inside Docker
#!/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