How to cache docker-compose build inside github-action
docker/build-push-action & want to access a cached image in subsequent steps -
load:trueto 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] with: push: false load: true set: | web.cache-from=type=gha web.cache-to=type=gha - name: Test via compose command: docker compose run web tests ...
services: web: build: context: . image: username/imagename command: echo "Test run successful!"
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: https://github.community/t/use-docker-layer-caching-with-docker-compose-build-not-just-docker/156049. The idea is to build the images using docker (and its cache) and then use docker compose to run (up) them.