Heroku container:push always re-installs conda packages Heroku container:push always re-installs conda packages heroku heroku

Heroku container:push always re-installs conda packages


This happens because once you updated the webapp directory, you invalidate the build cache. Whatever after this line needs to be rebuild.

When building an image, Docker steps through the instructions in your Dockerfile, executing each in the order specified. As each instruction is examined, Docker looks for an existing image in its cache that it can reuse, rather than creating a new (duplicate) image.

Once the cache is invalidated, all subsequent Dockerfile commands generate new images and the cache is not used. (docs)

Hence, to take advantage of the build cache your Dockerfile needs to be defined such as

FROM heroku/minicondaRUN conda install scikit-learn opencvADD ./webapp /opt/webapp/RUN pip install -qr /opt/webapp/requirements.txtWORKDIR /opt/webappCMD gunicorn --bind 0.0.0.0:$PORT wsgi

You should merge the two RUN conda commands to a single statement, to reduce number of layers in the image. Also, merge the ADD into single command and run pip requirements from a different directory.