How to cache docker-compose build inside github-action

If using docker/bake-action or docker/build-push-action & want to access a cached image in subsequent steps -

  • Use load:true to save the image
  • Use the same image name as the cached image across steps in order to skip rebuilds.


        name: Build and push
        uses: docker/[email protected]
          push: false
          load: true
        set: |
        name: Test via compose
        command: docker compose run web tests
      context: .
    image: username/imagename
    command: echo "Test run successful!"

See the docker team's responses;

  • How to access the bake-action cached image in subsequent steps?
  • How to use this plugin for a docker-compose?
  • How to share layers with Docker Compose?`
  • Experiment on caching docker compose images in GitHub Actions

What you are referring to is called "docker layer caching", and it is not yet natively supported in GitHub Actions.

This is discussed extensively in several places, like:

  • Cache docker image forum thread
  • Cache a Docker image built in workflow forum thread
  • Docker caching issue in actions/cache repository

As mentioned in the comments, there are some 3rd party actions that provide this functionality (like this one), but for such a core and fundamental feature, I would be cautious with anything that is not officially supported by GitHub itself.

For those arriving here via Google, this now "supported". Or at least it is working: The idea is to build the images using docker (and its cache) and then use docker compose to run (up) them.