buildx: --cache-from fails if cache does not already exist

could not read /tmp/buildx-cache/index.json: open /tmp/buildx-cache/index.json: no such file or directory

  docker buildx build \
    --cache-from type=local,src=/tmp/buildx-cache \
    --cache-to type=local,dest=/tmp/buildx-cache \
    .

Is --cache-from only supported when the cache already exists? That behavior would make no sense!

What am I missing?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 23
  • Comments: 17 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Hi I’m using

$ docker buildx version
github.com/docker/buildx v0.8.2-docker 6224def4dd2c3d347eee19db595348c50d7cb491

and I still get the same issue…

target "front" {
  inherits = ["defaults"]
  context="."
  tags = tag("nginx")
  cache-from = [
    "user/app:cache",
    "type=local,src=/tmp/buildx-cache"
  ]
  cache-to = ["type=local,dest=/tmp/buildx-cache"]
}

and when I build, I get:

$ docker buildx bake -f ./build.hcl --progress plain --push
[...]
 > importing cache manifest from user/app:cache:
------
------
 > exporting to image:
------
WARNING: local cache import at /tmp/buildx-cache not found due to err: could not read /tmp/buildx-cache/index.json: open /tmp/buildx-cache/index.json: no such file or directory

Do you have any idea for a workaround?

Tried with the master branch, but the problem persists.

This is a warning to let you know that nothing was loaded. It does not fail your build.

The reason why it’s broken is when you use --cache-from and --cache-to together, this line fails https://github.com/moby/buildkit/blob/master/client/solve.go#L432 if you run --cache-to on its own first, it will generate the json file and then you can add --cache-from after.

However this workaround is not feasible in e.g. CI/CD multibranch workflows, and should be fixed.

docker buildx create --driver docker-container --driver-opt image=moby/buildkit:master,network=host --use

docker buildx bake could not read .app-docker-cache/index.json: open .app-docker-cache/index.json: no such file or directory

With docker-bake.hcl containing:

group "default" {
  targets = ["app"]
}

target "app" {
  inherits = ["common"]
  args = {
    APP = "app"
  }

  context    = "."
  dockerfile = "docker/app/Dockerfile"
  target     = "app"
  cache-to   = ["type=local,dest=.app-docker-cache"]
  cache-from   = ["type=local,src=.app-docker-cache"]

  output = ["type=docker,name=app"]
}

this was fixed in https://github.com/moby/buildkit/pull/1285

You can switch to master build with --driver-opt if you want to use it now. https://github.com/docker/buildx#--driver-opt-options