Skip to content

Conversation

crazy-max
Copy link
Member

When trying to build a bake target with an empty Dockerfile:

target "default" {
  dockerfile = ""
}
$ docker buildx bake --print
#1 [internal] load local bake definitions
#1 reading docker-bake.hcl 39B / 39B done
#1 DONE 0.0s
{
  "group": {
    "default": {
      "targets": [
        "default"
      ]
    }
  },
  "target": {
    "default": {
      "context": ".",
      "dockerfile": ""
    }
  }
}
$ docker buildx bake
#0 building with "default" instance using docker driver

#1 [internal] load local bake definitions
#1 reading docker-bake.hcl 39B / 39B done
#1 DONE 0.0s

#2 [internal] load build definition from .
#2 transferring dockerfile: 132B done
#2 DONE 0.0s
ERROR: failed to solve: failed to read dockerfile: read /var/lib/docker/tmp/buildkit-mount205981038: is a directory

It doesn't set the default but tries to solve the working dir: load build definition from ..

When solving build opts in

buildx/bake/bake.go

Lines 1370 to 1376 in 1e50e8d

dockerfilePath := "Dockerfile"
if t.Dockerfile != nil {
dockerfilePath = *t.Dockerfile
}
if !strings.HasPrefix(dockerfilePath, "cwd://") {
dockerfilePath = path.Clean(dockerfilePath)
}

It will resolve to working dir (.) if empty: https://go.dev/play/p/yHTdZe5AXj8

With build command it sets Dockerfile if empty:

$ docker buildx build --file "" .                                                                                                      
#0 building with "default" instance using docker driver                                                                                                                                                        
                                                                                                                                                                                                               
#1 [internal] load build definition from Dockerfile                                                                                                                                                            
#1 transferring dockerfile: 49B done                                                                                                                                                                           
#1 DONE 0.0s

I think we should do the same with Bake and check for both nil and empty.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
@crazy-max crazy-max marked this pull request as ready for review July 31, 2025 08:21
@crazy-max crazy-max added this to the v0.27.0 milestone Aug 5, 2025
@crazy-max crazy-max merged commit 5743e3a into docker:master Aug 5, 2025
139 checks passed
@crazy-max crazy-max deleted the bake-frix-empty-dockerfile branch August 20, 2025 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants