Getting the following error in the first step of the Docker compose quick start guide. I know nothing about Docker compose so would appreciate some help:
➜ composetest docker compose up
[+] Running 1/0
Network composetest_default Created 0.0s
⠋ Container composetest-web-1 Created 0.0s
Attaching to web-1
web-1 | Usage: flask run [OPTIONS]
web-1 | Try ‘flask run --help’ for help.
web-1 |
web-1 | Error: Failed to find Flask application or factory in module ‘app’. Use ‘app:name’ to specify one.
web-1 exited with code 2
Folder structure and code is as follows. Very basic:
Neither the Dockerfile has an instruction to COPY your flask application into the image, nor does the compose file map the host folder containing the code into the container path /code.
So, how is the container supposed to access the flask app? You just copied the requirement and installed all dependencies, but never copied your application into the image.
I tried it now. It works perfectly. Check the instructions again and make sure you create all files correctly. For example the instruction shows two dependencies in the requirements.txt, you have one. The flask sourcecode is also different. Try the exact same files. If that works, then when you change it, it requires Python programming skills to make sure the source code is right. If the original code doesn’t work, we can try to find out what can affect it on your host to be different than on my host.
Yes I only have one because I was only trying to get the flask portion to work when i posted this question, no need having redis in the requirement.txt if I am not using it at all.
The point is that I can’t tell you by looking at the source code why it doesn’t work and the original code works. I didn’t have time for more testing and rewriting and I could not copy paste from the screenshot. I still recommend trying the original example. I didn’t need redis either, but I still tried
Hi!
This error happened to me when i run docker compose up for the first time and my lines of code has some error.
Try docker compose build and then docker compose up, the docker compose up make a build first and then he made the up, but only once in the time.
I hope it helps!