Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect to flask while running on docker container [duplicate]

I am trying to move a simple flask application to docker, but I can't see to figure out why the application is not accessible from the browser.

docker-compose file

version: '3'
services:
  web:
    build: .
    ports:
     - "5000:5000"
    volumes:
      - .:/app
    environment:
      FLASK_APP: api
      FLASK_ENV: development

  redis:
    image: "redis:alpine"

dockerfile

FROM python:3.7

ADD . /app
WORKDIR /app

RUN pip install -r requirements.txt
CMD ["flask", "run"]

__init__py:

def create_app(test_config=None):
  app = Flask(__name__, instance_relative_config=True)
  ...

  return app

result from docker-compose up --build

web_1    |  * Serving Flask app "api" (lazy loading)
web_1    |  * Environment: development
web_1    |  * Debug mode: on
web_1    |  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
web_1    |  * Restarting with stat
web_1    |  * Debugger is active!
web_1    |  * Debugger PIN: 277-205-758

But when I got to the browser:

The connection was reset

enter image description here

Any ideas why? I can't see what I am missing because the server is running but it does reset the connection right away...

Edit:

  • I did try to access it via localhost, 0.0.0.0, also using the container IP address
like image 662
Jorge Y. C. Rodriguez Avatar asked Feb 19 '19 23:02

Jorge Y. C. Rodriguez


1 Answers

Try

CMD ["flask", "run", "--host=0.0.0.0"]
like image 165
Dave W. Smith Avatar answered Oct 16 '22 18:10

Dave W. Smith