What I'm trying: I'm trying to run a simple flask app using docker. Using this site as a reference.
My dockerfile:
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY ./app /app
WORKDIR /app
RUN pip install -r "requirements.txt"
ENTRYPOINT ["python"]
CMD ["app.py"]
Python file:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!'
if __name__ == '__main__':
app.run(port=5000, debug=True)
requirements.txt:
Flask==1.0.2
What I'm doing:
docker build -t simple-flask2 .
docker run -p 5000:5000 simple-flask2
localhost:5000
nothing appears.docker exec -it 3be bash
& then did curl localhost:5000
. To my surprise it was working inside the container. Can anyone please point out what am I missing? I'm pretty new to this. TIA :)
I guess it is running only on the localhost (default value host='127.0.0.1'
) in the container. Try to use all interfaces (host='0.0.0.0'
):
if __name__ == '__main__':
app.run(port=5000, debug=True, host='0.0.0.0')
Try listening on every interface with:
app.run(host='0.0.0.0', port=5000, debug=True)
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