Gissipi_453
Gissipi_453

Reputation: 1330

Flask App with Gunicorn in production giving Error: socket hang up

I have a Flask app running as a Docker container using Gunicorn on a Paperspace server -

Dockerfile

FROM ubuntu:18.04
FROM python:3
RUN apt-get update -y && apt-get install -y python-pip python-dev
COPY . /backend
WORKDIR /backend
RUN pip3 install -r requirements.txt
EXPOSE 8000
CMD gunicorn --timeout 10000 --workers 4 --log-level debug --bind 0.0.0.0:8000 wsgi:app

app.py

#!/usr/bin/env python
# -*- coding: utf-8 -*- 
from flask import Flask, request

UPLOAD_FOLDER = '/uploads'
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
           
@app.route('/upload_file', methods=['GET', 'POST'])
def upload_file():
    return "it works fine"

wsgi.py

from api import app

if __name__ == '__main__':
    app.run()

I run it using

sudo docker run -it -p 8000:8000 myFlaskApp:1.28

On firing the API (/upload_file) from Postman, I'm getting

Error: socket hang up

But, this API works fine on localhost (http://0.0.0.0:8000)

Upvotes: 1

Views: 2317

Answers (1)

Simplecode
Simplecode

Reputation: 589

Try running the gunicorn server on it's own first in the terminal(without docker)

gunicorn -w xx -t xx -b 0.0.0.0:8080 wsgi:app

If gunicorn runs fine then its something wrong with the dockerfile. I think you should make ENTRYPOINT as gunicorn and then in CMD specify the params.

ENTRYPOINT ["gunicorn"]
CMD ["-w", "4", "-t", "10000", "-b", "0.0.0.0:8080", "wsgi:app"]

Upvotes: 1

Related Questions