Juju relations can be confusing or deceptively simple, at first. Some background is here: https://jujucharms.com/docs/stable/authors-hook-environment
juju run
runs commands in a Juju context, that is to say JUJU_CONTEXT_ID
environment variable is set.
$ juju run --unit haproxy/0 'echo $JUJU_CONTEXT_ID'
haproxy/0-juju-run-9100131373820979914
$ juju run --unit haproxy/0 'echo $JUJU_CONTEXT_ID'
haproxy/0-juju-run-8230555870602207522