Я пытаюсь настроить сервер Gunicorn внутри Ubuntu: последний образ Docker.
При запуске на Docker я получаю следующий результат:
[2020-08-01 14:12:38 +0000] [6] [INFO] Starting gunicorn 20.0.4
[2020-08-01 14:12:38 +0000] [6] [DEBUG] Arbiter booted
[2020-08-01 14:12:38 +0000] [6] [INFO] Listening at: http://0.0.0.0:5000 (6)
[2020-08-01 14:12:38 +0000] [6] [INFO] Using worker: sync
[2020-08-01 14:12:38 +0000] [8] [INFO] Booting worker with pid: 8
[2020-08-01 14:12:38 +0000] [6] [DEBUG] 1 workers
После что, я не вижу вывода на терминал. Я проверил порты, используя sudo netstat -tunlp
, открытый на моем компьютере, и Gunicorn не работает.
Он отлично работает, если я использую ту же настройку, используя gunicorn --bind 0.0.0.0:5000 app:app --log-level debug
внутри virtualenv ... Что-то мне не хватает вверх?
# ------------------------------------------------------------------------------
# Production image based on ubuntu:latest with nginx & python3
# ------------------------------------------------------------------------------
FROM ubuntu:latest as prod-react
WORKDIR /usr/src/app
# update, upgrade and install packages
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
RUN apt-get upgrade -y
RUN apt-get install -y nginx curl python3 python3-distutils python3-apt
# install pip
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
RUN python3 get-pip.py
# copy flask-api requirements file and install modules
COPY ./flask-api/requirements.txt ./
RUN pip install -r requirements.txt
RUN pip install gunicorn
# copy flask code
COPY ./flask-api/app.py .
# ------------------------------------------------------------------------------
# Serve flask-api with gunicorn
# ------------------------------------------------------------------------------
EXPOSE 5000
CMD gunicorn --bind 0.0.0.0:5000 app:app --log-level debug
Flask python код
from flask import Flask, request
from flask_cors import CORS
from flask_restful import Api, Resource
import time
# ------------------------------------------------------------------------------
# Flask app config + CORS
# ------------------------------------------------------------------------------
app = Flask(__name__)
app.config.from_object(__name__)
app.config['DEBUG'] = True
# accept CORS from frontend app
CORS(app, origins=['*'], supports_credentials=True)
# ------------------------------------------------------------------------------
# RESTFUL API
# ------------------------------------------------------------------------------
API_PREFIX = '/api'
api = Api(prefix=API_PREFIX)
class AuthenticationAPI(Resource):
def get(self):
print('auth get', flush=True)
return {'res': 'get'}, 200
def post(self):
print('auth post', flush=True)
print(request.get_json())
return {'res': 'post'}, 200
class TimeAPI(Resource):
def get(self):
print('time get', flush=True)
return {'res': time.time()}, 200
api.add_resource(AuthenticationAPI, '/auth')
api.add_resource(TimeAPI, '/time')
api.init_app(app)