I have a flask app that runs perfectly fine when using the simple terminal command flask run
, with the following directory structure:
flask-demo
│ Dockerfile
│ requirements.txt
│. start.sh
└───app
│ __init__.py
│ other-extensions.py
│
└───microservice-folders
│ │ ...
└───templates
│ │ ...
The content of __init__.py
contains
**imports**
def create_app(config_class=Config):
app = Flask(__name__)
app.config.from_object(config_class)
#manage login
***
# Initialize Flask extensions here
***
bs = Bootstrap(app) #flask-bootstrap
# Register blueprints here
***
return app
The content of Dockerfile
is:
FROM python:3.9
WORKDIR /python-docker
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
CMD ["flask", "run", "--host=0.0.0.0"]
This is what I always start with, and then from here I've tried many different iterations of how to actually run the docker container, but currently I am using a start.sh
script that looks like this:
#!/bin/zsh
app="docker.test"
docker build -t ${app} .
docker run -d -p 56733:80 \
--name=${app} \
-v $PWD:/app ${app}
And I then run zsh start.sh
in terminal. The container starts, as I get this output from docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
40c6b6dfca3a docker.test "flask run --host=0.…" 5 seconds ago Up 3 seconds 0.0.0.0:56733->80/tcp docker.test
However, when navigating to http://localhost:56733, I get the error "Safari cannot open the page http://localhost:56733 because it dropped the connection. This sometimes occurs when the server is busy. Wait a few minutes, then try again".
I've tried different iterations of Dockerfiles where I expose different ports, I've tried not using a start.sh
file and just using a docker run -d -p 56733:56733 docker.test
command, and I always get the same issue of the page just not loading.
EDIT: When I fixed the port problem by routing -p 8080:5000, I still get a completely blank screen.
EDIT2: I just had a friend pull my project from git and run it on his computer, and it actually works for him on his non-mac device. But it still does not work for me on my Mac.