Provide Dockerfile and all applicable config and base Flask scripts necessary to start a webpage, with a script to automate HTTPS re-configuration.
With this container, you can get an HTTP server setup in 2 commands, HTTPS in 4!
- Build the image: sudo docker build -t flaskwebpage .
- Run the container: sudo docker run -d -p 80:80 -p 443:443 --restart=always -t --name flaskwebpage flaskwebpage
- Connect to the container (optional): function _fu(){ sudo docker exec -i -t flaskwebpage /bin/bash ; };_fu
- Setup HTTPS (optional): /home/flask/conf/setup-https.py -d [domain_list_csv] -n [certname] -e [email_address]
https://www.mattsvensson.com/nerdings/2017/6/30/docker-flasknginxuwsgi
- 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 [email protected]
- 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
- Credit to Thatcher Peskens (https://github.com/atupal/dockerfile.flask-uwsgi-nginx), who this code was forked from.
- /home/flask/conf/setup-https.py -d test.com,www.test.com -n test.com -e [email protected]