Within an app composed of multiple microservices run via docker-compose, I need a way to make a request from one container (app
via flask & requests), directly to the other (chart
/django):
This is a simplified version of what I'm attempting.
routes.py:
@APP.route('/post_data', methods=['POST'])
def post_data():
post_data = request.get_json()
response = requests.post('http://chart_app_1:8080/json/', data=post_data)
return response.text
The response I get is an error message:
django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'chart_app_1:8080'. The domain name provided is not valid according to RFC 1034/1035
I'm able to make exactly this kind of request to other containers running flask apps, with no problems. I don't have any control over whether or not we use Django for this particular microservice though.
It seems that this might be because the hostname has an underscore in it: see this post. Is there a way around this? It seems like it must be possible to make a simple request between containers.
In the docker-compose file, modify the service name for avoiding underscores in the Django service.
That's the only way that I know for avoiding the error as it's not a Docker limitation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With