I am experiencing an issue with Docker layer caching in a GitHub Actions workflow. Specifically, the caching does not seem to work as expected for a step in my Dockerfile where I install Poetry using pip. The relevant part of my Dockerfile looks like this:
Dockerfile Copy code
... other parts of the Dockerfile ...
Install Poetry
RUN pip install --no-cache-dir poetry==1.7.0
... rest of the Dockerfile ...
When I build the Docker image locally on the same machine using the command docker build the layer caching works as expected, and the pip install step is cached between builds, given that nothing else has changed.
However, when I run the build within a GitHub Actions workflow on a self-hosted runner on the same machine, the pip install step does not seem to be cached, and it runs from scratch every time, significantly increasing the build time.
In my github action I'm using the docker build action, the cache-to and cache-from our way of doing the caching. I have verified that the versions of Docker and GitHub Actions runner are the same in both environments, and other steps in the Dockerfile appear to be cached correctly.
Why is the pip install step not being cached in the GitHub Actions workflow, and how can I fix this to reduce the build time?
I've tried doing the pip install with the numpy package as well and its not caching it as well, and I've tried running this on self hosted host and on the ubuntu-latest runner github are offering, out of ideas of why does it not being cached in the ci