I wrote a simple flask app and I want to deploy it to Heroku. After doing push and release, I look at the logs and see:
2020-09-20T14:32:06.077331+00:00 app[web.1]: *** Starting uWSGI 2.0.18 (64bit) on [Sun Sep 20 14:32:06 2020] ***
2020-09-20T14:32:06.077331+00:00 app[web.1]: compiled with version: 8.3.0 on 09 May 2020 21:28:24
2020-09-20T14:32:06.077331+00:00 app[web.1]: os: Linux-4.4.0-1076-aws #80-Ubuntu SMP Thu Aug 6 06:48:10 UTC 2020
2020-09-20T14:32:06.077335+00:00 app[web.1]: nodename: 8a7c5567-c468-4b88-aae5-7c8917589599
2020-09-20T14:32:06.077335+00:00 app[web.1]: machine: x86_64
2020-09-20T14:32:06.077336+00:00 app[web.1]: clock source: unix
2020-09-20T14:32:06.077336+00:00 app[web.1]: pcre jit disabled
2020-09-20T14:32:06.077337+00:00 app[web.1]: detected number of CPU cores: 8
2020-09-20T14:32:06.077337+00:00 app[web.1]: current working directory: /app
2020-09-20T14:32:06.077338+00:00 app[web.1]: detected binary path: /usr/local/bin/uwsgi
2020-09-20T14:32:06.077338+00:00 app[web.1]: your processes number limit is 256
2020-09-20T14:32:06.077338+00:00 app[web.1]: your memory page size is 4096 bytes
2020-09-20T14:32:06.077339+00:00 app[web.1]: detected max file descriptor number: 10000
2020-09-20T14:32:06.077339+00:00 app[web.1]: lock engine: pthread robust mutexes
2020-09-20T14:32:06.077455+00:00 app[web.1]: thunder lock: disabled (you can enable it with --thunder-lock)
2020-09-20T14:32:06.078001+00:00 app[web.1]: uwsgi socket 0 bound to TCP address :13940 fd 3
2020-09-20T14:32:06.078116+00:00 app[web.1]: unable to find user nginx
2020-09-20T14:32:06.078731+00:00 app[web.1]: 2020-09-20 14:32:06,078 INFO exited: uwsgi (exit status 1; not expected)
2020-09-20T14:32:07.081401+00:00 app[web.1]: 2020-09-20 14:32:07,081 INFO spawned: 'nginx' with pid 14
2020-09-20T14:32:07.082947+00:00 app[web.1]: 2020-09-20 14:32:07,082 INFO spawned: 'uwsgi' with pid 15
2020-09-20T14:32:07.089800+00:00 app[web.1]: 2020/09/20 14:32:07 [warn] 14#14: the "user" directive makes sense only if the master process runs with super
-user privileges, ignored in /etc/nginx/nginx.conf:1
2020-09-20T14:32:07.089801+00:00 app[web.1]: nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ig
nored in /etc/nginx/nginx.conf:1
2020-09-20T14:32:07.090605+00:00 app[web.1]: 2020/09/20 14:32:07 [emerg] 14#14: bind() to 0.0.0.0:80 failed (13: Permission denied)
2020-09-20T14:32:07.090606+00:00 app[web.1]: nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
2020-09-20T14:32:07.091044+00:00 app[web.1]: 2020-09-20 14:32:07,090 INFO exited: nginx (exit status 1; not expected)
2020-09-20T14:32:07.093198+00:00 app[web.1]: [uWSGI] getting INI configuration from /app/uwsgi.ini
2020-09-20T14:32:07.093264+00:00 app[web.1]: 2020-09-20 14:32:07,093 INFO gave up: nginx entered FATAL state, too many start retries too quickly
2020-09-20T14:32:07.093377+00:00 app[web.1]: [uWSGI] getting INI configuration from /etc/uwsgi/uwsgi.ini
As it seems, it fails to bind port 80. This is my __ main __:
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
webapp.run(debug=True, host='0.0.0.0', port=port)
This is my uswgi.init:
[uwsgi]
module = app.ourtale
callable = webapp
master=true
http-socket = :$(PORT)
This is my procfile:
web: uwsgi --http-socket :$PORT --ini uwsgi.ini
And this is my dockerfile:
FROM tiangolo/uwsgi-nginx-flask:python3.6
COPY requirements.txt /tmp/
RUN pip install -U pip
RUN pip install -r /tmp/requirements.txt
USER nginx //EDIT: Added this line, but it doesn't seem fix the "unable to find user nginx"
COPY . /app
Any idea why it fails to bind port 80? Thanks in advance
UPDATE: I added
ENV LISTEN_PORT 8080
EXPOSE 8080
And it seem to fix the no-permission problem. But it still seem to crash. These are the logs:
2020-09-20T18:14:00.337298+00:00 app[web.1]: *** Starting uWSGI 2.0.18 (64bit) on [Sun Sep 20 18:14:00 2020] ***
2020-09-20T18:14:00.337298+00:00 app[web.1]: compiled with version: 8.3.0 on 09 May 2020 21:28:24
2020-09-20T18:14:00.337299+00:00 app[web.1]: os: Linux-4.4.0-1076-aws #80-Ubuntu SMP Thu Aug 6 06:48:10 UTC 2020
2020-09-20T18:14:00.337300+00:00 app[web.1]: nodename: bb979578-c952-46fc-9710-02e06bbfe136
2020-09-20T18:14:00.337300+00:00 app[web.1]: machine: x86_64
2020-09-20T18:14:00.337301+00:00 app[web.1]: clock source: unix
2020-09-20T18:14:00.337301+00:00 app[web.1]: pcre jit disabled
2020-09-20T18:14:00.337301+00:00 app[web.1]: detected number of CPU cores: 8
2020-09-20T18:14:00.337302+00:00 app[web.1]: current working directory: /app
2020-09-20T18:14:00.337302+00:00 app[web.1]: detected binary path: /usr/local/bin/uwsgi
2020-09-20T18:14:00.337303+00:00 app[web.1]: your processes number limit is 256
2020-09-20T18:14:00.337303+00:00 app[web.1]: your memory page size is 4096 bytes
2020-09-20T18:14:00.337304+00:00 app[web.1]: detected max file descriptor number: 10000
2020-09-20T18:14:00.337304+00:00 app[web.1]: lock engine: pthread robust mutexes
2020-09-20T18:14:00.337398+00:00 app[web.1]: thunder lock: disabled (you can enable it with --thunder-lock)
2020-09-20T18:14:00.337835+00:00 app[web.1]: uwsgi socket 0 bound to TCP address :13532 fd 3
2020-09-20T18:14:00.337932+00:00 app[web.1]: unable to find user nginx
2020-09-20T18:14:00.338440+00:00 app[web.1]: 2020-09-20 18:14:00,338 INFO exited: uwsgi (exit status 1; not expected)
2020-09-20T18:14:01.339776+00:00 app[web.1]: 2020-09-20 18:14:01,339 INFO gave up: uwsgi entered FATAL state, too many start retries too quickly
2020-09-20T18:14:51.678718+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-09-20T18:14:51.698324+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-09-20T18:14:51.807290+00:00 heroku[web.1]: Process exited with status 137
2020-09-20T18:14:51.849446+00:00 heroku[web.1]: State changed from starting to crashed
It looks like it tries to find unsuccessfully a user called 'nginx'
Ports less than 1024 are privileged ports and requires root user privileges to bind. I guess you are not running entrypoint as root user.
Try updating the default port nginx will bind to for HTTP like this: https://github.com/tiangolo/uwsgi-nginx-flask-docker#custom-listen-port
This will not matter as long as you map port 80(outside) to this custom port when you run docker run
.