I have a Flask/Connexion application that provides a UI in Flask and an API via Connexion. When I run it using the default Flask server, everything runs fine – I see my UI and can call my API. However, when I run it from a Docker container I still get the Flask UI but every one of my API calls is routed to my Flask 404 error handler. In the error handler, I print out the URLs using str(request.url) and can see that the URL being called is correct. Why is connexion not routing these calls to the handlers specified in my api.json file?
Here’s the line in my Dockerfile that runs my application…
CMD ["sh", "-c", "uvicorn flask_startup:asgi_app --host $HOST --port $PORT"]
This code appears at the top of my flask application (flask_startup.py)…
connexion_app = connexion.FlaskApp(__name__, auth_all_paths=True, specification_dir='./')
connexion_app.add_api('api.json') # Read the swagger.json file to configure the endpoints for the API
app = connexion_app.app
asgi_app = WsgiToAsgi(app)
I enter the following in my browser (to bring up the swagger UI)…
http://0.0.0.0:5001/api/v1.0/ui
And find the following info generated by uvicorn…
INFO: 192.168.65.1:58487 – “GET /api/v1.0/ui HTTP/1.1” 404 Not Found
This happens regardless of which URL endpoint I call. FWIW, when I go to the following in my browser…
http://0.0.0.0:5001/
my flask UI appears.
Keep in mind that this all works fine if I skip Docker and just run my code with the default flask server.
Any ideas on what’s missing & how I can get flask/connexion to recognize my API calls? Thanks!
1