Search code examples
pythonpipdockerfigrequirements.txt

Do I always need to rebuild docker in order to install new pip packages?


I noticed when I try to use docker ( Fig mainly ) to install a new pip package, it does not actually maintain on the system. I must rebuild and install the pip package from requirements.txt

I tried running fig run web pip install django and I see the package install, but every time I run the command it reinstalls without prompting to upgrade ( So I know the package install did not stick )

Is this just the inherit design of Docker? I'm confused why building is always necessary


Solution

  • You should read the documentation for Dockerfiles https://docs.docker.com/reference/builder.

    You should be running

    sudo fig build
    

    with a Dockerfile that resembles

    FROM centos:centos7 # or whatever
    RUN yum -y install python-pip
    RUN pip install bottle # or whatever  
    

    In short, modifications to the file system do not persist container runs. You need to either build a new image or use a volume.