I have an error when I use docker, when I build my image, my Mongodb database launches but my python server does not launch and I get the following error:
2023-03-21 14:11:25 Traceback (most recent call last):
2023-03-21 14:11:25 File "/app/ServeurWeb.py", line 5, in <module>
2023-03-21 14:11:25 from flask_restful import Api, Resource, reqparse
2023-03-21 14:11:25 ModuleNotFoundError: No module named 'flask_restful'
However flask_restful is installed on my computer with the command
pip install flask_restful
2
Answers
pip install flask_restful
needs to be ran inside of your Dockerfile. Your host does not share packages with the image.Ideally, you use a
requirements.txt
file, instead, however.create a
requirements.txt
file in the same directory asDockerfile
.add
flask_restful
in the requirements.txt file.Then add the below code in your dockerfile.
Note that if you install flask_restful in your host system, your docker container won’t recognize that as docker container runs on a isolated environment.