Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker flask cant connect

I am trying to do http://containertutorials.com/docker-compose/flask-simple-app.html

I have copied the tutorial verbatim, except I changed

From flask import Flask

to

from flask import Flask

I can built it just fine. I can start it and get the following when I run docker ps from the command line

CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS                    NAMES
291c8dfe5ddb        whatever:latest     "python app.py"     About a minute ago   Up About a minute   0.0.0.0:5000->5000/tcp   sick_wozniak

I am building this on OSX

I have tried the following

  1. Looking at this post Deploying a minimal flask app in docker - server connection issues
  2. Running $ python app.py to make sure it works without docker
  3. Creating a django project and a dockerfile for that project. Then build, run and access.

So I am confident that docker is working and flask is working independently of each other, but I cannot get them to work together.

like image 289
humanbeing Avatar asked Feb 07 '23 11:02

humanbeing


1 Answers

If on Linux, then http://localhost:5000 should work seeing as the container is both running and listening on port 5000.

Otherwise, you would be using Docker Machine, and so you need to get the IP of the docker virtual machine using docker-machine ip. On OSX, for example

$ open http://$(docker-machine ip default):5000
like image 115
OneCricketeer Avatar answered Feb 12 '23 10:02

OneCricketeer