# Accessing containers within the same service

**URL:** <https://forums.suse.com/t/accessing-containers-within-the-same-service/867>\
**Category:** Rancher 1.x\
**Created:** [November 4, 2015, 12:53pm UTC](https://forums.suse.com/t/accessing-containers-within-the-same-service/867 "2015-11-04T12:53:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jack](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/jack/32/466_2.png) [@Jack](https://forums.suse.com/u/Jack)\
**Post date:** [November 4, 2015, 12:53pm UTC](https://forums.suse.com/t/accessing-containers-within-the-same-service/867/1 "2015-11-04T12:53:50Z")

</div>

'ello folks!

Think I’ve got a fun one for you all here. I’m looking at clustering RabbitMQ across multiple hosts without having to explicitly tell each service to cluster with another. I’d like for me to add a host and scale up the _RabbitMQ_ service which will automatically find another _RabbitMQ_ container and cluster with it.

I understand with the new _Rancher_ metadata stuff I can get information about other containers within a service, but I’m struggling with a DNS issue.

When a _RabbitMQ_ server starts, it sets its “node name” to `rabbit@HOSTNAME`, which usually comes out as something like `rabbit@9d3302e323c1` within _Docker_. When another server wants to cluster with that, it _must_ refer to the first server with _the same name_.

This means that if `rabbit@123` wants to cluster with `rabbit@abc`, `abc` needs to point to whatever IP is relevant.

As far as I’ve seen, you can’t change the hostname that _RabbitMQ_ uses (it uses the `HOSTNAME` environment variable, but I assume changing this would cause some… oddities).

So, any ideas?

Feel free to bombard me with any questions; I’m sure I haven’t explained the situation as thoroughly as I could’ve!

Thanks

---

<div class="post-metadata">

**Author:** ![mishak](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/mishak/32/412_2.png) [@mishak](https://forums.suse.com/u/mishak)\
**Post date:** [November 5, 2015, 7:06pm UTC](https://forums.suse.com/t/accessing-containers-within-the-same-service/867/2 "2015-11-05T19:06:31Z")

</div>

Have a look at [labels](http://docs.rancher.com/rancher/labels/) especially `io.rancher.container.hostname_override:	container_name`.  
It is useful when deploying containers one per host ie.: [elasticsearch nodes](https://github.com/rancher/compose-templates/blob/master/elasticsearch/0.3.1/docker-compose.yml#L4).

---

<div class="post-metadata">

**Author:** ![Jack](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/jack/32/466_2.png) [@Jack](https://forums.suse.com/u/Jack)\
**Post date:** [November 6, 2015, 9:36am UTC](https://forums.suse.com/t/accessing-containers-within-the-same-service/867/3 "2015-11-06T09:36:23Z")

</div>

Heya @mishak! Thanks for the reply!

Found that little gem earlier and the containers to indeed set the _RabbitMQ_ “node name” to something like `rabbit@MyStack_RabbitMQ_1` which is awesome!

Problem is, other containers within that same service can’t seem to access the container from that hostname; they can access it via the internal IP fine, just the hostname isn’t in their `/etc/hosts` file! 😛

I’m assuming it’d be bad for me to be editing that on the fly?

---

<div class="post-metadata">

**Author:** ![mishak](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/mishak/32/412_2.png) [@mishak](https://forums.suse.com/u/mishak)\
**Post date:** [November 6, 2015, 3:29pm UTC](https://forums.suse.com/t/accessing-containers-within-the-same-service/867/4 "2015-11-06T15:29:52Z")

</div>

What about defining external service for that stack with ip of that rabbitmq node? 🙂  
That way services can reffer to it as rabbit in their `external_links: [rabbitmq]`.

---

<div class="post-metadata">

**Author:** ![Jack](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/jack/32/466_2.png) [@Jack](https://forums.suse.com/u/Jack)\
**Post date:** [November 19, 2015, 10:13am UTC](https://forums.suse.com/t/accessing-containers-within-the-same-service/867/5 "2015-11-19T10:13:05Z")

</div>

Apologies for the exceedingly late reply! Tried that too and couldn’t get the hostnames to match up still.

Looks like `0.46.0` might quell my woes with its new DNS features, though! If I get this set up I’ll post how (as I know there’s nothing worse than finding a forum thread on what you want to do and finding “Nevermind. Fixed!”)!

---

<div class="post-metadata">

**Author:** ![dsvmacdonald](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@dsvmacdonald](https://forums.suse.com/u/dsvmacdonald)\
**Post date:** [November 21, 2015, 8:39pm UTC](https://forums.suse.com/t/accessing-containers-within-the-same-service/867/6 "2015-11-21T20:39:42Z")

</div>

I created a docker image for running RabbitMQ with Rancher. It uses the Rancher Metadata Service to allow RabbitMQ to scale, restart and add back after a crash.

[Link with image and source details/link](http://forums.suse.com/t/how-do-you-setup-a-cluster/816/5?u=dsvmacdonald)
