question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Export layers to "regular" docker

See original GitHub issue

Hi, 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:closed
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nmattiacommented, Jan 17, 2022

Thanks for all the help here, really appreciated! The workflow is much simpler and about twice as fast. Got yourself a new sponsor 😃

0reactions
crazy-maxcommented, Jan 17, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

docker export - Docker Documentation
The docker export command does not export the contents of volumes associated with the container. If a volume is mounted on top of...
Read more >
docker: extracting a layer from a image - Stack Overflow
It works by using a patched version of the docker daemon inside a docker image that can access the images on your host...
Read more >
Docker import/export vs. load/save - PSPDFKit
In this post, we'll look at the differences between Docker's import / export and load / save commands. It's intended for relative newcomers...
Read more >
Long running exporting layers step when using 'usermod' in ...
When using usermod in a Dockerfile I sometimes run into long build times in the "exporting layers" step and an image with a...
Read more >
Difference Between Docker Save and Export - Baeldung
The save command preserves the image layer information, including all history and metadata. This allows us to fully import the tar file into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found