I have a simple python web application like below which I am trying to containerize in a docker container and run. The endpoints '/' and '/es' works as this is hosted on localhost.
I have a website in IIS with custom hostname as www.devtenant1.local:777 which maps to 127.0.0.1 in my host machine hosts file. How can I access this website from docker container which is running on host machine with custom hostname?
Code below
import json
from flask import Flask
import requests
app = Flask(__name__)
@app.route("/") *#this works*
def main():
return "Welcome!"
@app.route("/es") *#this works*
def connect_to_es():
result = requests.get("http://host.docker.internal:9200/")
return result.json()
@app.route("/values") *#this doesn't work. What should be my URL in get() below*
def get_values():
headers = {'content-type': 'application/json'}
result = requests.get("https://www.devtenant1.local:777/api/values", headers=headers, verify=False)
return result.json()
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0')
I tried adding below host entries inside the container using docker run
or docker build
but it doesn't work -
- --add-host=www.devtenant1.local:172.17.0.1 (Gateway)
- --add-host=www.devtenant1.local:172.17.0.2 (IPAddress)
- --add-host=www.devtenant1.local:0.0.0.0 (from one of the suggestions)
- --add-host=www.devtenant1.local:10.1.10.160 (from one of the suggestions)