如何让 bazel 的 rules_docker 使用存储库缓存

How to get bazel's rules_docker to use the repository cache

(这是一个自问自答的问题:答案很简单,但我没有轻易找到它:这是解决这个问题的尝试)

如果您通过 container_pull 与 Bazel 和 rules_docker 依赖 docker 容器,您似乎需要相对频繁地重新下载 docker 图像。对于数百 Mb 的图像,这尤其成问题。

看起来 rules_docker 忽略了 --repository_cache 配置标志。

解决方法见下文。

rules_docker将只缓存到DOCKER_REPO_CACHE指定的路径,如果设置了。

有关警告的 container_pull 请参阅 this documentation page

NOTE: Set DOCKER_REPO_CACHE env variable to make the container puller cache downloaded layers at the directory specified as a value to this env variable. The caching feature hasn't been thoroughly tested and may be thread unsafe. If you notice flakiness after enabling it, see the warning below on how to workaround it.

NOTE: container_pull is suspected to have thread safety issues. To ensure multiple container_pull(s) don't execute concurrently, please use the bazel startup flag --loading_phase_threads=1 in your bazel invocation (typically by adding startup --loading_phase_threads=1 as a line in your .bazelrc)