我把我的Flask 应用程序停靠在了Windows上.我使用Docker Desktop来运行Docker.在Windows中,要加入容器,只能使用IP"192.168.99.100",而不能使用本地主机.因此,在对接APP后,我try 从该IP地址访问一个API,但请求超时:
The strange thing is that I enabled debug inside my main.py file, but when I run docker-compose up, it seems that it doesnt' run the application in debug mode:
我的Dockerfile,在其中我指定了在哪里可以找到我的main.py应用程序(与flaskapp相同的路径):
FROM python:3.8
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8080
ENV FLASK_APP=main.py
CMD ["flask", "run", "--host", "0.0.0.0"]
Docker-compose.yaml
version: "3"
services:
api:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
expose:
- "8080"
volumes:
- .:/app
stdin_open: true
environment:
- FLASK_APP=main.py
- GOOGLE_APPLICATION_CREDENTIALS=cred.json
Docker-compose.yaml and Dockerfile are in the same path.
Py,在那里您可以看到我在调试模式下运行它的最后几行:
import os, io
import logging
import json
import jinja2
import requests
import re
from flask import Flask, request, render_template, send_file, abort, session, redirect, jsonify, url_for
from flask_cors import CORS
from flask.helpers import make_response
from google.cloud import tasks_v2, bigquery, firestore, kms_v1, storage
import httplib2shim
import env_config
from audience_manager import AudienceManager
from datetime import datetime, timedelta
import time
import mysql.connector
import cron
from google.cloud import pubsub_v1
import google.oauth2.credentials
from googleapiclient.discovery import build
from google.auth import app_engine
import google_auth_oauthlib.flow
from exceptions import AuthenticatorException, UserVisibilityNotFoundException, InvalidEmailException, \
NoneEmailException
from jwt.exceptions import ExpiredSignatureError
from authlib.integrations.base_client import MismatchingStateError
from authlib.integrations.flask_client import OAuth
from oauth2_authentication import Oauth2Authentication
from services import db_service
from spreadsheet import Spreadsheet
from ggm import start_ggm_check, ggm_module
import secret_manager_module
from flask.globals import g
from task_module import CloudTask
import iap_service
httplib2shim.patch()
app = Flask(__name__)
@app.before_request
def before_request():
print("#### abc")
g.auth_user = "giacomo.brunetta@external.stellantis.com"
@app.route('/hello', methods=['POST'])
def ciao():
print("## hello")
return 'ok'
if __name__ == "__main__":
app.run(host='127.0.0.1', port=8080, debug=True)
要求中的Flask 版本为2.0.1