I am running a Cookiecutter django project in a docker environment and I would like to add new packages via pip. Specifically I want to add: djangorestframework-jwt
When I do:
docker-compose -f local.yml run --rm django pip install
it seems like it would be perfectly working because I get:
Successfully installed PyJWT-1.7.1 djangorestframework-jwt-1.11.0
Now the problem is that it doesn't install it. It doesn't appear when I run pip freeze, and also not in pip list
Then I tried to put it into my requirements.txt file and run it with:
docker-compose -f local.yml run --rm django pip install -r requirements/base.txt
Same result. It says that it is successfully installed but it is not. I thought it might be a problem with my django version and the package, but the same happens when I try to update my pip. It says it updated, but when I run pip install -upgrade pip I get again:
You should consider upgrading via the 'pip install --upgrade pip' command.
docker-compose run starts a new container and executes the command in it. When used with --rm flag the container gets removed after command completes.
What happens is you get a new container created, and packages installed, or pip upgraded, inside this container. Once the command completes the container is removed.
If later on you run something like docker-compose -f local.yml run --rm pip list a brand new container will get created and pip list executed inside it, showing no packages from previous run since they were installed in a different container, which is already removed.
A better way would be to create docker image that includes your application and install pip packages during docker build. You can check a sample in this question
This way any time you start a container from your image it will have all packages inside.