How to update Docker interpreter when requirements.txt is updated?
I have managed to get a Docker interpreter working in PyCharm and now I want to install a new library. Normally, when using a venv I would just go and add the library to requirements.txt, that lists the project dependencies, and then
pip install requirements.txt
to update the environment with the added library. However, now I'm using a Docker environment, I'm not sure what to do after updating requirments.txt with the new library. I expected that PyCharm would detect the update to requirements.txt and use this to build a new image when I next spin up an instance (e.g. run or new interpreter), but it did not and the new library is not available. On the other hand, pip installing in the Docker instance would only work for the current instance as the changes would be lost as soon as a new instance is spun up. So what are the correct workflow steps here after updating requirements.txt?
请先登录再写评论。
Hello,
Usually, a good practice to add lines like this to the Dockerfile:
You can modify them to fit your project/image structure, but the common idea is to copy your requirements.txt to the image and then run pip install against it every time you rebuild the image.
This also makes your Dockerfile universal and allows you to use it outside your dev environment.
Hi Daniil,
This is what I have in my Dockerfile:
However, now when I update requirements.txt with a new library and launch a new interpreter, it seems to be using the old build and so the library is not installed. Is there a way to have PyCharm detect changes to requirements.txt and rebuild the image automatically?
Oh, I see, but I can't reproduce the issue, and changes in requirements.txt affect image building.
Could you please clarify if you are using a docker or a docker-compose interpreter?