Nginx With Dokku and Flask

The Big Picture

I have a Flask site which– previously– was running successfully on Ubuntu on Linode. I bootstrapped it with Yeoman, and as a result, I did not need to figure out the difference between nginx, wsgi/Werkzeug, and gunicorn.

However, that is biting me in the butt now that I’m trying to migrate it to my first Digitalocean droplet, using their pre-configured disk image of Ubuntu 16.04 with Dokku 0.7.2. This is my first time with Docker or Dokku, or containerization in general.

Dokku did not give an error when deploying my Flask app– it told me the app is running on my droplet’s IP address followed by :17520. (I am not using a domain name, just the IP address.)

Problem Definition

My site does not respond to HTTP requests, despite Dokku saying it succeeded in deployment. Chrome says “This site can’t be reached”.

Solutions I’ve Already Tried

It took a few tries for Dokku to deploy my app without an error, because I needed to add some files to the root of my local repository and try pushing it again.

The Procfile

First I needed Procfile, which contains the single line web: python run.py where run.py is:

from app import app
app.run(host = '0.0.0.0', debug = True)

Ignoring My Node.js Dev Tooling

Next I needed to prevent Dokku from seeing my Node.js development tooling and trying to deploy this as a Node.js app. So I added .slugignore containing the single line package.json, and .buildpacks containing the single line https://github.com/heroku/heroku-buildpack-python and pushed again to git push dokku.

Gunicorn

Yeoman did not include gunicorn when I bootstrapped this app– just nginx and wsgi/Werkzeug. I noticed all Python Procfile examples used gunicorn as the HTTP server, so I added gunicorn==0.17.2 to my requirements.txt. I changedProcfiletoweb: gunicorn app:app`. Dokku did not throw an error when installing this version, but there is still no response to HTTP requests.

Logs

Dokku log

When I log on to my droplet and run the command dokku log [my_app_name], it says:

2017-01-17T17:11:04.733185275Z app[web.1]: * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
2017-01-17T17:11:04.734938531Z app[web.1]: * Restarting with stat
2017-01-17T17:11:05.024834922Z app[web.1]: * Debugger is active!
2017-01-17T17:11:05.029750092Z app[web.1]: * Debugger pin code: 208-261-801

So I also tried to append :5000 to the IP address. And of course, just to be safe, I tried port 80 too. Still no luck.

After I installed gunicorn, the log read:

2017-01-18T17:09:38.303046670Z app[web.1]: 2017-01-18 17:09:38 [8] [INFO] Starting gunicorn 0.17.2
2017-01-18T17:09:38.303864158Z app[web.1]: 2017-01-18 17:09:38 [8] [INFO] Listening at: http://0.0.0.0:5000 (8)
2017-01-18T17:09:38.304140278Z app[web.1]: 2017-01-18 17:09:38 [8] [INFO] Using worker: sync
2017-01-18T17:09:38.310057688Z app[web.1]: 2017-01-18 17:09:38 [148] [INFO] Booting worker with pid: 148

Events.log

Still logged in to my droplet, I went to var/log/dokku and opened the file events.log, ending with this:
Jan 17 16:27:55 [my-app-name] dokku-installer.py[7291]: 127.0.0.1 - - [17/Jan/2017 16:27:55] "GET /favicon.ico HTTP/1.0" 200 -
Jan 17 16:28:27 [my-app-name] dokku-installer.py[7291]: 127.0.0.1 - - [17/Jan/2017 16:28:27] "HEAD / HTTP/1.0" 200 -
Jan 17 16:29:49 [my-app-name] dokku-installer.py[7291]: SHA256: [then the SHA]
Jan 17 16:29:50 [my-app-name] dokku-installer.py[7291]: 127.0.0.1 - - [17/Jan/2017 16:29:50] "POST /setup HTTP/1.0" 200 -
Jan 17 16:29:50 [my-app-name] dokku-installer.py[7291]: Stopping nginx (via systemctl): nginx.service.
Jan 17 16:29:51 [my-app-name] dokku-installer.py[7291]: Starting nginx (via systemctl): nginx.service.
Jan 17 16:29:51 [my-app-name] dokku-installer.py[7291]: /bin/sh: 1: stop: not found

Related:


Leave a Reply