2

I have a Flask app running with docker and uwsgi on AWS. I have some endpoints and when I do a POST to one of them, using Postman or Curl, I see on the logs the response status code 412, but on Postman or Curl it shows 502.

I tried to run the Flask app locally without docker but using uwsgi, and it runs as expected.

I need to have a 412 response to know how to handle this status code.

vitorh45
  • 21
  • 1
  • Can you provide more detail on your environment? Are you using load balancers, API gateway, etc? It sounds like the response is being altered by something between the web server and the requester. – bwest Jan 29 '19 at 21:40
  • I imagined something like that, but the infra guy is too busy since the beginning of this week and couldn't help me so far. But thx for you answer. – vitorh45 Jan 30 '19 at 14:48

1 Answers1

1

If the flask app works as expected on your local machine, it might have something to do with how the port routing is setup for your container.

In addition to the port your flask application is receiving requests on, there is a Docker container that it lives inside that also has its own ports. The first is an external set of ports that need to be exposed to receive requests, and there's another set of internal ports that can be linked to external ports and used by your application.

The long explanation is available in this answer here, but the TLDR is:

Running your container with docker run -it --expose 8008 -p 8008:8008 myContainer will allow for an externally exposed port with --expose EXTERNALPORT and will bind the internal container port to the external container port with -p INTERNALPORT:EXTERNALPORT.

Lastly, when running your flask service, you'll need to make sure that its port lines up with the internally exposed container port. An example using the same port we listed before would be:

flask run --host=0.0.0.0 --port=8008

Nick Walsh
  • 1,807
  • 5
  • 16