I have made a basic temperature converter web app using python Flask and when i am running in using the command `python3 main.py Then it is runnning fine. But after building dockerfile and running in container it is not running dockerfile is build completely with no error and also the port mapping is correctly done
My flask app is running properly in the local host but when i try running in docker container it is not able to run in the mapped port
Here is the python code in main.py file
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route("/")
def index():
celsius = request.args.get("celsius", "")
if celsius:
fahrenheit = fahrenheit_from(celsius)
else:
fahrenheit = ""
return (
"""<form action="" method="get">
Celsius temperature: <input type="text" name="celsius">
<input type="submit" value="Convert to Fahrenheit">
</form>"""
+ "Fahrenheit: "
+ fahrenheit
)
def fahrenheit_from(celsius):
"""Convert Celsius to Fahrenheit degrees."""
try:
fahrenheit = float(celsius) * 9 / 5 + 32
fahrenheit = round(fahrenheit, 3) # Round to three decimal places
return str(fahrenheit)
except ValueError:
return "invalid input"
if __name__ == "__main__":
app.run(host="127.0.0.1", port=3000, debug=True)
`
Here is the DockerFile code