Documentation: setting array values with `bake --set`
Original Issue (please see edit below)
Steps to reproduce
- Create an empty dir
- Add a
Dockerfile:
FROM centos:8
- Add a
docker-bake.hcl:
group "default" {
targets = ["image"]
}
target "image" {
context = "."
}
- Run docker
buildx bake --set "*.tags=image_name_1" --load image- this passes as expected and loadsimage_1:latestinto the local docker instance - Run
docker buildx bake --set "*.tags=image_name_1,image_name_2" --load image- this fails with:
[+] Building 0.0s (0/0)
error: invalid tag "image_name_1,image_name_2": invalid reference format
Expected behaviour
Based on the plural name, and looking at the code, I believe the intent is for target.tags to be an array - am I using the wrong separator or is this a bug?
Edit
Ok so I realised to set multiple tags you need to specify multiple values in the command the same as you would for tag in a build invocation (https://github.com/docker/buildx/issues/396). I.e. you can get this working with:
docker buildx bake --set "*.tags=image_name_1" --set "*.tags=image_name_2" image
For context the reason I felt so sure I needed to use a csv was because I had been successfully using a csv when setting platform via set, for example this works fine:
docker buildx bake --set "*.tags=image_name_1" --set "*.platform=linux/amd64,linux/arm64" image
and I assumed all array type overrides would be formatted the same way.
I'm going to leave this open for now as a question and/or documentation issue. At the moment the bake docs don't give any examples of setting array values and as they only give a single type for --set (stringArray) don't really explain the type/format for the individual overrides - this seems important especially as there does seem to be differences (e.g. platform vs tag).
I particularly had a hard time to get around it as well... It would be great if this is well documented with examples...
Similar comment regarding docker buildx bake -f, where -f takes a stringArray. I want to pass in multiple docker-bake.json files.
In the a docker-bake.hcl file, we would set the tags like this:
# docker-bake.hcl
target "webapp-dev" {
dockerfile = "Dockerfile.webapp"
tags = ["docker.io/username/webapp:latest"]
}
Where tags takes an array. So, I expected the arg to --set to accept an array, e.g. docker buildx bake --set 'webapp-dev.tags=[foo/bar:latest,foo/bar:v1.2.3]', that didn't work and searching I found this issue.
I would have expected repeating args, that the last arg would override the previous args. I think it makes more sense that the arg is an array, like the HCL syntax.
It turns out shell brace expansion is a pretty good fit here, so maybe we can document that? e.g. docker buildx bake all --set=\*.tags=foo/bar:{baz,qux}.