So there are a number of different things you can do.
1: Just mount your rez package repo dir(s) into your container. The upside to this is that images stay small, and you don't need different images to use different packages. The downside is that you're pulling package source from some filesystem outside of your container, which doesn't really make it very contained! But, whatever works for you. At Method we do this a lot of the time.
https://docs.docker.com/storage/bind-mounts/
2: You can use rez-cp to copy all the packages that a context uses, into another package repo. Then, when constructing the image (via dockerfile), you would COPY this dedicated package repo into your container. Now, you can perform a rez-env in the container, and point it at this repo. The image now contains only the package you're using.
As of version 2.60.0, you can do this:
]$ rez-env pkgA pkgB -o - | rez-context --print-resolve --su - | xargs -i rez-cp --variant-uri {} --dest-path ./mytestrepo
Ie:
* resolve an env, and write it to stdout
* read a context from stdin, and print the URIs of each variant
* use rez-cp to copy each variant into package repo ./mytestrepo
In your dockerfile then, you may want to run the following commands:
mkdir /packages # make local rez pkg repo
rez-env pkgA pkgB -o - | rez-context --print-resolve --su - | xargs -i rez-cp --variant-uri {} --dest-path /packages
rez-env --nl --paths /packages -o runtime.rxt
Now, to run your command in docker, you'd run "rez-env -i runtime.rxt -- somecommand".
All that of course depends on your packages being relocatable. If you have compiled packages that do any rpathed linking for eg, that may not be true.
3: rez-build stuff directly into your container. Note that you'd have to rez-build all the dependencies in bottom-to-top order. Rez-build doesn't fetch dependencies or anything like that. Ultimately I'd like to have a rez-install tool that does that - it would perform much the same function as pip for eg - but that's a larger topic and there's a lot of work to be done there.
4: Another approach could be to do something similar to (2), but copy the packages to the docker host instead of the image, and to bind mount that local host path. That would mean you don't need different images for each resolve, but you would also avoid mounting to shared storage somewhere. However you'd have to ensure that this package repo is available on every host your container might run on.
In short, rez and docker aren't mutually exclusive at all. What you want to do specifically depends on a number of factors and hopefully the suggestions above get you on your way.
Hth
A