1

Below is my DockerFile:

FROM python:3.8.5
COPY . /usr/app/
EXPOSE 5500
WORKDIR /usr/app/
RUN pip install -r requirements.txt
CMD python app.py

I am running this container using the command "docker run -p 5500:5500 api_name", after which I get the below message in cmd: C:\Users\win10\Documents\ML files>docker run -p 5500:5500 api_name

  • Serving Flask app "app" (lazy loading)
  • Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
  • Debug mode: on
  • Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
  • Restarting with stat
  • Debugger is active!
  • Debugger PIN: xxx-xxx-xxx

I tried accessing http://127.0.0.1:5000/ or http://127.0.0.1:5500/ but "This site can’t be reached". PS: I am using docker desktop for windows

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • Your port mapping is mapping port 5500 on host to 5500 on container, but your container logs say it's listening on 5000. You to map to port 5000 of the container: `-p 5500:5000` then it will be accessible on localhost:5500 – zigarn Mar 12 '21 at 07:25
  • https://docs.docker.com/config/containers/container-networking/ – zigarn Mar 12 '21 at 07:25
  • (you should also adapt the value of the `EXPOSE` to reflect the port the containerized app is listening on) – zigarn Mar 12 '21 at 07:27

1 Answers1

0

Without inspecting your app.py file, it is difficult to say for sure. However, most likely your app is not listening on the correct port, or the correct binding host. By default, flask apps listen on 127.0.0.1, and when running inside a docker container, you need to listen to 0.0.0.0, using app.run(host='0.0.0.0')

Here is a working sample

Dockerfile

FROM python:3.8.5
COPY . /usr/app/
EXPOSE 5000
WORKDIR /usr/app/
RUN pip install flask
CMD python app.py

app.py

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run(host='0.0.0.0')

Build and run

$ docker build -t temp
$ docker run -p 5000:5000 temp
DannyB
  • 12,810
  • 5
  • 55
  • 65