Reputation: 999
My goal is to create image by Dockerfile and than run container from that image.
This is Dockerfile:
FROM python:3-alpine
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 2000
CMD ["python", "app.py"]
This is 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", port=5000)
I am building image with this command: docker build -t flask:v1 .
And running it with this command: docker run -p 5000:2000 flask:v1
After I run it, I get this in terminal:
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 265-965-329
When I go to http://0.0.0.0:5000/
, browser returns me:
This site can’t be reached
As I understood, when running -p 5000:2000
, 5000 is host port and 2000 is container port.
And command EXPOSE
in Dockerfile
is exposing container port.
Why do I get This site can’t be reached
when I exposed correctly container port and binded it with host port 5000?
Upvotes: 0
Views: 1481
Reputation: 729
Because your app is running on port 5000
app.run(debug=True, host="0.0.0.0", port=5000)
So you should map that port to your outside port like this
docker run -p 5000:5000 flask:v1
As I understood, when running -p 5000:2000, 5000 is host port and 2000 is container port. And command EXPOSE in Dockerfile is exposing container port.
Yes but since your app is running on port 5000 there is nothing running on port 2000. You can also change that port in app.run
if you want to use the 2000 port
Upvotes: 3