question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image not cached using Docker caching example from docs

See original GitHub issue

Behaviour

Using the example workflow from the docs to build with a buildx local cache directory that is then kept in the Github Actions cache results in Docker layers still being downloaded by buildx. The workflow’s “Cache Docker Layers” step successfully restores the cache once it is warmed up, but the “Build and push” step shows layers being downloaded.

Steps to reproduce this issue

  1. Create a new repo with a simple Dockerfile.
  2. Add a Github Actions workflow using the example workflow from the docs.
  3. Push an update to trigger a build and warm the cache.
  4. Push another update to trigger another build.

Expected behaviour

The base image specified in the Dockerfile should be in buildx’s cache and the buildx logs should simply show “CACHED” after processing the FROM line.

Actual behaviour

The logs show “CACHED” but then show the progress lines of various layers of the base image being downloaded.

Configuration

The only change from the example workflow config is that push is disabled. I tried with push enabled but hit an auth issue with Dockerhub which is beyond the scope of this issue. Also, even in that build, the cache issue was still present.

# from https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md
name: ci

on:
  push:
    branches:
      - 'main'

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v2
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Cache Docker layers
        uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-
      -
        name: Login to DockerHub
        uses: docker/login-action@v1 
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      -
        name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: .
          push: false
          tags: user/app:latest
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
      -
        # Temp fix
        # https://github.com/docker/build-push-action/issues/252
        # https://github.com/moby/buildkit/issues/1896
        name: Move cache
        run: |
          rm -rf /tmp/.buildx-cache
          mv /tmp/.buildx-cache-new /tmp/.buildx-cache

Logs

1_docker.txt

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mnoble-vodycommented, Feb 12, 2022

I see. It ends up taking a significant amount of time processing the cached blobs, to the point where it is faster to not using the cache. Any ideas on why this would be going so slowly? This is running on the Github Actions hosted runners.

0reactions
tonistiigicommented, Feb 11, 2022

Are you aware of this one

Yes, I remember this was reported on some issue. But I don’t know what conditions cause it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optimizing builds with cache management
The only way to force a rebuild is by making sure that a layer before it has changed, or by clearing the build...
Read more >
Docker layer caching - Semaphore 2.0 Documentation
The --cache-from command line option in the docker command allows you to build a new image using a pre-existing one as the cache...
Read more >
Enabling Docker Layer Caching - CircleCI
DLC caches the individual layers of any Docker images built during your CircleCI jobs, and then reuses unchanged image layers on subsequent CircleCI...
Read more >
Pulling cached Docker Hub images - Google Cloud
Container Registry caches frequently-accessed public Docker Hub images on mirror.gcr.io . You can configure the Docker daemon to use a cached public image...
Read more >
Pipeline caching · Codefresh | Docs
When you build images locally, Docker will cache intermediate layers making ... Note that if you are using Codefresh on-prem, this kind of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found