Skip to content

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

License

Notifications You must be signed in to change notification settings

malcolmmackay/docker-flask-nginx-uwsgi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 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?:

(Be sure docker is isntalled. If not installed, run install_docker.sh)

With this container and a built image (or pulling the image from ucnt/flaskwebpage), you can get an HTTP or HTTPS server setup in 1 commands

  • HTTP: sudo docker run -d -p 80:80 -p 443:443 --restart=always -t --name flaskwebpage flaskwebpage
  • HTTPS (change parameters): sudo docker run -d -p 80:80 -p 443:443 --restart=always -t --name flaskwebpage flaskwebpage "-d example.com,www.example.com -n example.com -e my@email.com"

Notes:

  • If you arleady setupt he server as HTTP and you want HTTPS, run: /home/flask/conf/setup-https.py -d [domain_list_csv] -n [certname] -e [email_address]
  • You can access the container via: sudo docker exec -i -t flaskwebpage /bin/bash

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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 89.9%
  • Shell 5.8%
  • HTML 4.3%