2

I am trying to run Flask in Docker. The containers seem to be running but the browser can't connect.

docker-compose.yml:

version: '3'

services: 
  api:
    build: .
    ports:
      - "5000:5000"
    volumes:
      - ./src:/usr/src

Dockerfile:

FROM python:3.8.2
COPY ./src /usr/src
WORKDIR /usr/src
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["run.py"]
from flask import Flask

def create_app(config_filename):
    app = Flask(__name__)
    app.config.from_object(config_filename)

    from app import api_bp
    app.register_blueprint(api_bp, url_prefix='/api')

    return app

if __name__ == "__main__":
    app = create_app("config")
    app.run(debug=True)

When I try to go to http://localhost:5000/api/Hello, I get:

chrome page isn't working error

davidism
  • 121,510
  • 29
  • 395
  • 339
BluePrint
  • 1,926
  • 4
  • 28
  • 49

1 Answers1

4

I had a similar problem and I solved it adding the host to the app.run:

app.run(host="0.0.0.0", debug=True)
ionpoint
  • 861
  • 6
  • 10