Past an environmental variable from one container to another

I am currently dockerizing a micro-service application and using Consul for service discovery. So all the services register themselves with the consul and also get their environmental variables from the consul. The starting script of the undockerized micro service application takes the Consul ip:port from the user and forwards it to all the other microservices which is good. But how do I replicate the same for dockerized microservice application as each container is independent. Also, all the services need to register themselves with the consul but they don’t have the consul ip.

I can hardcode the consul ip:port in each of the required microservice application but I don’ t think that’s an elegant way. So do you have any idea on how to make other services aware of the consul ip?

Any help is appreciated.

if you have two docker containers A and B.
And you link B to use A.
Then A’s env is mapped into B.