Skip to content

Docker container for Flask, Nginx, and uWSGI, with letsencrypt for HTTPS

Notifications You must be signed in to change notification settings

OptimusKe/docker-flask-nginx-uwsgi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker container for Flask, Nginx, and uWSGI, + Letsencrypt's certbot-auto for HTTPS

Purpose:

Provide Dockerfile and all applicable config and base Flask scripts necessary to start a webpage, with a script to automate HTTPS re-configuration.

Why do I use it?:

With this container, you can get an HTTP server setup in 2 commands, HTTPS in 4!

  1. Build the image: sudo docker build -t flaskwebpage .
  2. Run the container: sudo docker run -d -p 80:80 -p 443:443 --restart=always -t --name flaskwebpage flaskwebpage
  3. Connect to the container (optional): function _fu(){ sudo docker exec -i -t flaskwebpage /bin/bash ; };_fu
  4. Setup HTTPS (optional): /home/flask/conf/setup-https.py -d [domain_list_csv] -n [certname] -e [email_address]

More thoughts:

https://www.mattsvensson.com/nerdings/2017/6/30/docker-flasknginxuwsgi

Notes/Details:

  • Folder/File Sctructure
    • All of the files+folders in this repo will be, by default, put into /home/flask. If you modify this you need to update the Dockerfile.
    • The /home/flask/app folder will contain the Flask app. As long as the wsgi.py file uses "app" not "application," you can swap in and out any flask app that you want (so long as you have the necessary libraries installed).

  • Services/Notes
    • This script uses linux's Supervisor to monitor and control uWSGI and nginx.
    • Port 443 is left on the run command in case you want to use it. If you never will, you can remove "-p 443:443"

  • HTTPS Setup Options (assumes 1 domain per container instance)
    • Do it the easy way! Go into the container and run a command like one of the below examples to automate the setup via a custom script I wrote. Before running it, yes, you should own the domain and have updated the DNS records.
    • - /home/flask/conf/setup-https.py -d test.com -n test.com -e test@test.com
      - /home/flask/conf/setup-https.py -d test.com,www.test.com -n test.com -e test@test.com
    • Do it the hard way: - Run "/home/flask/certbot-auto certonly -d [domain] -w /home/flask/app"
      - Adjust /home/flask/conf/nginx-http.conf to use HTTPS or modify /home/flask/conf/nginx-https.conf, remove /etc/nginx/sites-enabled/nginx-http.conf, re-link ntinx-https.conf to /etc/nginx/sites-enabled
      - Test and restart the supervisor service

  • Credits

About

Docker container for Flask, Nginx, and uWSGI, with letsencrypt for HTTPS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published