Docker exec environment different to container shell
Please refer to bash initialization process.
https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html

In your Dockerfile, at lines 12-14 you are patching files, but do not activate any of rbenvs.
Later at your last RUN call, you finally ARE activating an rbenv. This starts pointing at that specific version of ruby (I thin this patches root files)
At that point you have different global shell initialization files vs. user initialization files.

Difference


entry point: "non-login" initialization process happens, then the file: /root/.bashrc is executed (a.k.a. "sourced"), it points to your cool ruby
exec of ruby: ruby executable is located using your default PATH. without running /root/.bash* files.


To validate all this you can append printouts to your shell's initialization files, and see what gets printed upon 2 cases.

Regards.