Export layers to "regular" docker
See original GitHub issueHi, thanks for the great action!
I’ve been trying to figure out how to export a buildx
build to Docker that includes the layers. Right now I use load: true
which allows me to run e.g. docker run
subsequently, however now I’m trying to figure out how to export the layers as well.
I have a 2-step build. The first step is a build-push-action
build that is cached between runs (using cache-to
and saved with actions/cache
). My second build is not cached, and re-uses the layers from the first build with cache-from
. This second build is saved to docker (through load: true
), so I can use docker run
and other commands (build file below).
While I need build-push-action
in the first build step (in order to export and cache the layers), I’d like to not use it in the second step, and use a regular docker build
instead. The reason is that the second step wastes about a minute importing the output with cache-from
. Unfortunately, I noticed that when I save the image with load: true
, a subsequent docker build
won’t be able to re-use the layers, but will see the image as a whole. Is there a way to export the layers from buildx so that I can use them in a regular docker build
?
- uses: actions/checkout@v2
- name: Set up docker buildx
uses: docker/setup-buildx-action@v1
- name: Cache docker layers
uses: actions/cache@v2
id: docker-cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles( '.dockerignore', 'Dockerfile', ...) }}
- name: Build base Docker image
uses: docker/build-push-action@v2
with:
tags: my-image-cached
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: ${{ (! steps.docker-cache.outputs.cache-hit) && 'type=local,dest=/tmp/.buildx-cache-new,mode=max' || '' }}
target: cached # the cached bits are e.g. FROM ubuntu AS cached
# https://github.com/docker/build-push-action/issues/252
- name: Move cache
run: |
if [ -d /tmp/.buildx-cache-new ]
then
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
fi
- name: Build final docker image
uses: docker/build-push-action@v2
with:
tags: my-image
load: true # effectively makes the image usable in 'docker run'
cache-from: type=local,src=/tmp/.buildx-cache
- run: docker run my-image ...
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (6 by maintainers)
Top GitHub Comments
Thanks for all the help here, really appreciated! The workflow is much simpler and about twice as fast. Got yourself a new sponsor 😃
You’re welcome, see also https://github.com/dfinity/nns-dapp/pull/357#pullrequestreview-854258755 to export artifacts as it seems it’s what you want so it removes the
load
overhead.