Use Docker layer caching with docker-compose build (not just docker) #25728
-
Hi, I spent some time getting my workflows to work with the docker layer caching as described in the blog by Docker: Docker Github Actions - Docker Blog This works fine for building the images with Docker:
And I have 1 more container build like that (step2). I have a docker-compose setup to run unit tests & integration tests with a whole bunch of docker-compose specific config around environment variables, volumes, entrypoints, etc. So I am running these tests using docker-compose. Problem is docker-compose doesn’t use the images built by Docker. I did a lot of searching and googling and tried lots of things, but everything I found doesn’t seem to help to get it to work in GitHub actions. Latest try (after the docker build steps above):
Doesn’t help, docker compose starts rebuilding both containers from scratch. Also doing Anyone knows the solution? Could be that I’m missing something, but most examples of docker layer caching (with github actions) doesn’t seem to cover docker-compose. Full workflow and runs here: Docker caching by valentijnscholten · Pull Request #60 · valentijnscholten/django-DefectDojo · GitHub Valentijn |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 1 reply
-
Added a basic PoC here where I build with docker-build-push action and then use docker-compose up with --no-build Locally on my machine this works fine. Docker-compose uses the images build by docker. On GitHub actions it doesn’t work. the jobs fails as it says the image is not there. github.comvalentijnscholten/docker-cachingpoc. Contribute to valentijnscholten/docker-caching development by creating an account on GitHub. |
Beta Was this translation helpful? Give feedback.
-
ok, found the solution. I realized that maybe the docker-build-and-push action didn’t actually do anything with the generated image, i.e. it was not made available to the runner / docker. Turns out this is true and even documented: github.comdocker/build-push-action - Export image to DockerGitHub Action to build and push Docker images with Buildx Once you know what you’re looking for, it’s easy… In case the link dies, the solution is to add
|
Beta Was this translation helpful? Give feedback.
-
Note that there’s a bug that makes the cache grow and grow if you do it this way. There’s a fix here. |
Beta Was this translation helpful? Give feedback.
-
I struggled to get this working - docker-compose would not pick up on the cache content, in spite of following the suggestions around using the However, I did find a 3rd party option that might be suitable for anyone having similar problems to me: github.comsatackey/action-docker-layer-caching🐳 Enable Docker layer caching in GitHub Actions. Contribute to satackey/action-docker-layer-caching development by creating an account on GitHub. I do recommend using the documented step of pulling images, as the caching was much slower when I omitted it on my first run through. Oddly I found that docker-compose ignored the
|
Beta Was this translation helpful? Give feedback.
-
This is not working … I have build args in docker-compose and it is not providing on the builds… Also, the logs doesn’t show any indication… I would expect that the library called “docker buildx bake | Docker Documentation” buildx bake… |
Beta Was this translation helpful? Give feedback.
-
Awesome! It works. Just don’t keep in mind that the tag in Action workflow and specified image name in the docker-compose.yml have to be the same. Otherwise, it rebuilds the image instead of using cache. |
Beta Was this translation helpful? Give feedback.
ok, found the solution. I realized that maybe the docker-build-and-push action didn’t actually do anything with the generated image, i.e. it was not made available to the runner / docker. Turns out this is true and even documented:
github.comdocker/build-push-action - Export image to Docker
GitHub Action to build and push Docker images with Buildx
Once you know what you’re looking for, it’s easy…
In case the link dies, the solution is to add
load: True
to the docker-build-and-push action: