Speed up pip downloads in Docker with BuildKit’s new caching
Docker uses layer caching to speed up builds, but layer caching isn’t always enough.
When you’re rapidly developing your Python application and therefore frequently changing the list of dependencies, you’re going to end up downloading the same packages.
Over and over and over again.
This is no fun when you depend on small packages.
It’s extra no fun when you’re downloading machine learning libraries that take hundreds of megabytes.
With the release of a stable Docker BuildKit, Docker now supports a new caching mechanism that can cache these downloads.
The problem: when caching doesn’t help
Let’s say you have some code with a requirements.txt
listing dependencies:
And a Dockerfile
that uses it to install dependencies: