Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bake: unclear path resolution when setting both dockerfile and context for a target #2839

Open
3 tasks done
RogWilco opened this issue Dec 4, 2024 · 0 comments
Open
3 tasks done

Comments

@RogWilco
Copy link

RogWilco commented Dec 4, 2024

Contributing guidelines

I've found a bug and checked that ...

  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

I’ve encountered what seems to be unexpected behavior regarding the dockerfile and context target attributes in a docker-bake.hcl file.

  • When dockerfile is set to a path relative to the docker-bake.hcl file, everything works as expected, and the build succeeds.

  • However, when the context attribute is set to a subdirectory, the build fails with the following error:

    ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory
    

It appears that the dockerfile path is treated as relative to the context directory, not the docker-bake.hcl file. While this behavior is logical in isolation, it is inconsistent with how paths are handled in other tools like docker-compose.yaml, where both attributes are interpreted as relative to the file defining them.

Expected behaviour

Both dockerfile and context (and by extension contexts) should consistently resolve relative paths from the docker-bake.hcl file to maintain consistency across the toolset.

Alternatively the docs could be updated to explicitly explain the relationship between these attributes.

Actual behaviour

The dockerfile path is unexpectedly relative to the context, causing the build to fail when context is set.

Buildx version

github.com/docker/buildx v0.17.1-desktop.1 1a2ee7e8d945b88fdc18f1948da491c2f540dec9

Docker info


Builders list

NAME/NODE           DRIVER/ENDPOINT     STATUS    BUILDKIT   PLATFORMS
default             docker
 \_ default          \_ default         running   v0.16.0    linux/arm64, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64
desktop-linux*      docker
 \_ desktop-linux    \_ desktop-linux   running   v0.16.0    linux/arm64, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64

Configuration

This issue arose while working in a monorepo with multiple Lambda functions sharing a single Dockerfile. Here’s an example structure:

./
├── lambdas/
│   ├── some_lambda_function/
│   │   └── ...source-files
│   └── some_other_lambda_function/
│       └── ...source-files
├── docker-bake.hcl
└── Dockerfile

Example docker-bake.hcl

group "default" {
  targets = ["some_lambda_function", "some_other_lambda_function"]
  flags = ["--provenance=false"]
}

target "some_lambda_function" {
  dockerfile = "Dockerfile"
  context = "lambdas/some_lambda_function"
  tags = [ "latest" ]
}

target "some_other_lambda_function" {
  dockerfile = "Dockerfile"
  context = "lambdas/some_other_lambda_function"
  tags = [ "latest" ]
}

Build logs


Additional info

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant