I have a flask app that runs a couple of things based on the user call. In this app, I also have one basic endpoint that just returns a string which would help me to see if the app is running or not.
@app.route("/hello")
def hello():
return "Hello World!"
Now I tried to dockerize this app using this tutorial from the official docker site. The flask app listens on the port 5000 and so I added an entry in my Dockerfile to expose the port 5000.
EXPOSE 5000
And the command that I am using in the Dockerfile to run the app is
CMD ["python","model.py"]
model.py file has the flask code that calls other functions based on the user input.
Now when I run my app after containerizing it, I see the required output on the terminal that the flask app is indeed running. This is the command that I used to run the app.
docker run -p 5000:5000 firstContainer
When I try to call the basic helloWorld method above by using the request http://localhost:5000/hello, I get an error message saying that the site is unavailable. Is there anything that I am doing wrong wrt the port mappings here? How do I fix this issue ?
EDIT: Adding more details
So I tried to go into the container to see what's happening and I was able to view the files that were available on the container and they look good. When I tried to start the app again in the container using the base command
python model.py
it returned an error saying that the port is already in use. So this should mean that the app is indeed listening on the port. I also installed curl inside the container to browse the URL and it returned the expected string when I ran it inside the container. I just don't understand how I can expose it to outside world
EDIT 2:
Container logs
* Serving Flask app "model" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on