Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 4

Cache a Docker image built in workflow

Solved! Go to Solution.

We're currently building a Docker image every workflow run. This takes 10-15 minutes. It's faster to fetch the same image from Docker hub, but nicer to only be dependent on the Dockerfile in the repo. Is there any way to speed up subsequent builds by doing some kind of Docker build caching?

3 Replies
GitHub Staff
Message 2 of 4

Re: Cache a Docker image built in workflow

We're adding caching.  It will arrive by mid-November.


See also

Ground Controller Lvl 1
Message 3 of 4

Re: Cache a Docker image built in workflow

For those who found this Subject looking for a way to use cache in Workflows, you can use this action that does just what @nergnezor mentioned: fetches the layers from a Registry and use (multiple) --cache-from to hint docker where to look for cache.


The action supports multi-stage builds as it pushes each stage to a registry, and pull them when a new build is triggered.


This is a minimal example:


- uses: whoan/docker-build-with-cache-action@v1
    username: whoan
    password: "${{ secrets.DOCKER_PASSWORD }}"
    image_name: whoan/node
Pilot Lvl 1
Message 4 of 4

Re: Cache a Docker image built in workflow

Using buildx and ghaction-docker-buildx does not require to set cache or to push to registry:


name: buildx

    branches: master
    branches: master

    runs-on: ubuntu-latest
        name: Checkout
        uses: actions/checkout@v1
        name: Set up Docker Buildx
        id: buildx
        uses: crazy-max/ghaction-docker-buildx@master
          version: latest
        name: Available platforms
        run: echo ${{ steps.buildx.outputs.platforms }}
        name: Run Buildx
        run: |
          docker buildx build \
            --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x \
            --output "type=image,push=false" \
            --file ./test/Dockerfile ./test


Live example: