Create a Dockerized Flask boilerplate with Gunicorn behind Nginx. The Docker Compose setup needs a healthcheck that curls /health and auto-restarts after 3 failures. Configure logrotate for access logs.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Prepared a full set of files for a Flask app running Gunicorn behind Nginx, with Compose healthcheck curling /health, restart policy, and a logrotate config for Nginx access logs included. Next, I'll output each file's content and a brief usage note.
Below is a minimal boilerplate that runs a Flask app with Gunicorn behind Nginx, uses Docker Compose with a /health endpoint health check (3 retries), and rotates Nginx access logs via logrotate.
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/")
def index():
return "Hello from Flask behind Nginx/Gunicorn!"
@app.route("/health")
def health():
# add any checks you need here
return jsonify(status="ok"), 200
if __name__ == "__main__":
# only for local debugging
app.run(host="0.0.0.0", port=8000)
Health check hits http://localhost:8000/health inside the web container; retries: 3 ensures Docker marks the container as unhealthy after 3 consecutive failures. restart: on-failure:3 will try up to 3 restarts if the container exits. Docker does not auto-restart simply on failed health checks; exit the process if you want Docker to restart it.
The logrotate sidecar uses Alpine’s logrotate plus crond to rotate Nginx logs in the nginx-logs volume. Adjust the schedule or policy in logrotate/nginx as needed.