With {dev_mode, true} in rebar.config everything works as it supposed to.
With {dev_mode, false} it works this way:
on the first run of the app the relx startup script creates new vm.args with correct values of the environment variables and renames old vm.args to vm.args.orig. So far so good.
on the second run with different values of the environment variables it keeps old values in the vm.args and overwrites vm.args.orig with vm.args, which contains values left from the first run.
So values of the cookie and node name can't be changed after the first run. And original vm.args with variables such as ${COOKIE} gets deleted for good after the second run of the release.
Related issue: https://github.com/erlware/relx/issues/243
With {dev_mode, true} in rebar.config everything works as it supposed to. With {dev_mode, false} it works this way: