buildx icon indicating copy to clipboard operation
buildx copied to clipboard

buildx bake does not tag docker-compose images

Open jcfj opened this issue 4 years ago • 3 comments

When I build the images for a compose file, buildx bake will export them, but not tag them. e.g.:

$ docker buildx bake
[…]
$ docker image list
REPOSITORY                       TAG                        IMAGE ID       CREATED              SIZE
<none>                           <none>                     b8c0f7d34127   About a minute ago   810MB
<none>                           <none>                     ebd3ca4c54c5   2 minutes ago        806MB

I can work around this with some jq:

$ docker buildx bake -f <(docker buildx bake -f docker-compose.yml --print | jq --arg name "$(basename "$PWD")" '{group: .group, target: (.target|to_entries|[.[]|{(.key):(.value + {"tags":[$name + "_" + .key]})}]|add)}')
[…]
$ docker image list
REPOSITORY                       TAG                        IMAGE ID       CREATED         SIZE
asdf_bsdf                        latest                     b8c0f7d34127   2 minutes ago   810MB
asdf_csdf                        latest                     ebd3ca4c54c5   3 minutes ago   806MB

and docker-compose will correctly use these images and not try to build them again.

But shouldn't this be done by default?

Misc

$ docker buildx version
github.com/docker/buildx v0.7.1-docker 05846896d149da05f3d6fd1e7770da187b52a247

[Edit]

I suppose I could use x-bake this for that (but then I lose the flexibility of having multiple project names (docker-compose -p) from the same compose file), or --set, which is tedious. I guess that makes this a feature request to

  • automatically tag on a folder name derived project-name
  • add a cli parameter that allows to override the default project-name

jcfj avatar Jan 05 '22 01:01 jcfj

You should set image: in the yaml, even if you don't intend to push the tags. This will then be used as a tag by bake and as the run image by compose (be careful not to up --pull in that case)

ciaranmcnulty avatar Apr 05 '22 13:04 ciaranmcnulty

Docker-compose build now seems to use buildkit by default (This changed with 2.4.1 for me, but I'm not sure whether that's global or just something weird with my installation.) If someone can confirm that this is global, I think using docker-compose build instead of docker buildx bake is just fine and this can be closed.

(And can we please not make comments like "What the other guy posted fixed it for me too" but just give a 👍 to that comment instead @NadimYounes? I'd like to not receive notifications for that kind of thing…)

jcfj avatar Apr 19 '22 00:04 jcfj