I am running a flask app using Pycharm and I get the following message: INFO:werkzeug: * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
I have been trying to access the website from my local browser and it’s not working. First, I tried the following in Pycharm and it didn’t work: “RUN > Edit configuration > Docker deployment > Container > Add port binding > container port=5000 > host port=5000”. Is this right? should I add something in Host IP?
I also tried to access the API URL in the build, execution > docker, but it’s not working.
What is the easier way to solve this problem?
app.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "Hello World!"
if __name__ == "__main__":
app.run(debug=True,host='0.0.0.0')
you can provide host ip directly
requirements.txt
Flask==0.10.1
Dockerfile
FROM ubuntu:16.04
MAINTANER Your Name "[email protected]"
RUN apt-get update -y && \
apt-get install -y python-pip python-dev
#your Dockerfile is missing this line
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY . /app
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]
docker commands to run
docker build -t flaskapp:latest .
#flask runs in default port 5000
docker run -d -p 5000:5000 flaskapp
In browser: http://localhost:5000
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