Skip to content
Advertisement

Docker run error – Failed to find Flask application or factory in module “app”. Use “FLASK_APP=app:name to specify one

trying to dockerize this flask app… running the following

docker build --tag flask-website .

works, output successfully built, successfully tagged.

edit: the next command works

JavaScript

ok, so then I run curl localhost:5000

which gives this error

JavaScript

ok straight forward enough, so then I try this

docker-compose up

and this results

JavaScript

however trying to navigate to localhost:5000 I get

JavaScript

directory structure looks like this

JavaScript

dockerfile looks like this

JavaScript

I had tried with EXPOSE 5000 uncommented and commented, making no difference

I also updated the directory structure and dockerfile, which got rid of the command line error I was seeing

docker-compose looks like this

JavaScript

I tried with the dockerfile, docker-compose, makefile, and requirements outside of the app directory and a slightly modified dockerfile on the WORKDIR line, that resulted in this error

JavaScript

not sure what else to try? I can run it locally with python -m flask run, but I cannot seem to dockerize it, seems like this should not be this difficult?

for completeness sake, app.py looks like this

JavaScript

util.py looks like this

JavaScript

I have also tried both ways with the pickle import in util, same result – I thought because I was building it in a docker container that the second import was correct

I have also tried this block for app.run as well with the same result

JavaScript

Advertisement

Answer

ok the following changes were required to get this image to build and the container to run

dockerfile:

JavaScript

then the following change to the main application app.py

JavaScript

then to util.py, which had an error I did not see until running docker run [TAG]

JavaScript

then run docker build -t [TAG] . then run docker-compose up

then navigate to localhost listening on port 5000 and there is the running container

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement