Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaning unnecessary pip cache #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aminvakil
Copy link

https://pip.pypa.io/en/stable/reference/pip_install/#caching

It's almost 30MB difference in a 3GB docker image:)
But it's safe to use and I can't think of a situation where pip cache in creating this image is needed.

@johndpope
Copy link

While this will help the pip cache - it will invalidate the image for stylegan2 in dockers' build cache
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache

this means in practical terms - many users will need to refetch / rebuild gigabytes of data. It adds up if / when you have more than one image using stylegan2 base dockerfile.

@aminvakil
Copy link
Author

aminvakil commented Apr 24, 2020

Just to clarify what does my commit do:

pip install --no-cache-dir is suitable in two situations:

  1. When you want to be sure you're installing the latest version of the package from pip repo. By default if the package you want to install has been installed before and it hasn't expired yet (From pip documentation: When storing items in the cache, pip will respect the CacheControl header if it exists, or it will fall back to the Expires header if that exists. This allows pip to function as a browser would, and allows the index server to communicate to pip how long it is reasonable to cache any particular item.), pip will install the downloaded package from cache.

  2. When you don't want to cache the packages you're installing, this is the scenario which is meant here in this commit. We don't want our image to keep pip cache, because it isn't needed later.

This has nothing to do with docker build cache that you have said, docker doesn't care what you're doing in each RUN in your Dockerfile, it will build another layer after each command that you've written in your Dockerfile, whether it's just an ls or it's pip install package or pip install --no-cache-dir package, the only difference here is that the layer which docker creates with the committed Dockerfile is smaller than the main Dockerfile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants