# Multicontainer unable resolve service names

**URL:** <https://forums.balena.io/t/multicontainer-unable-resolve-service-names/197095>\
**Category:** Product support\
**Tags:** docker, network\
**Created:** [October 8, 2020, 12:01pm UTC](https://forums.balena.io/t/multicontainer-unable-resolve-service-names/197095 "2020-10-08T12:01:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![wnnb](https://avatars.discourse-cdn.com/v4/letter/w/958977/32.png) [@wnnb](https://forums.balena.io/u/wnnb)\
**Post date:** [October 8, 2020, 12:01pm UTC](https://forums.balena.io/t/multicontainer-unable-resolve-service-names/197095/1 "2020-10-08T12:01:34Z")

</div>

From one container we are not able to resolve another one based on service names.  
We could use port nat in the docker-compose and resolve on “localhost” but different ports for different containers. But Do we have other options?

So far we have tried adding “hostname:” with the same name as service name to the service, and have also tried to have all services in ‘bridge’ or ‘host’ without this making any difference.

If it is not clear what we try to do, from service-b we would like to run command “curl service-a/index.html”

```auto
version: '2.1'
services:
  service-a:
    build: ./service-a
    network_mode: "host"
    hostname: service-a
    network_mode: "host"
    ports:
      - "80:80"
  service-b:
    build: ./service-b
    hostname: service-b
    network_mode: "bridge"
  service-c:
    build: ./service-c
    network_mode: "bridge" 
    hostname: service-c
    expose: 
      - "8080"

```

---

<div class="post-metadata">

**Author:** ![dfunckt](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dfunckt/32/56_2.png) [@dfunckt](https://forums.balena.io/u/dfunckt)\
**Post date:** [October 8, 2020, 12:11pm UTC](https://forums.balena.io/t/multicontainer-unable-resolve-service-names/197095/5 "2020-10-08T12:11:39Z")

</div>

It doesn’t work that way. Have a look at network/aliases: [https://docs.docker.com/compose/compose-file/compose-file-v2/#aliases](https://docs.docker.com/compose/compose-file/compose-file-v2/#aliases) . What this basically does is expose the container on the specified network under the specified hostname which you can use to refer to from inside other containers.

---

<div class="post-metadata">

**Author:** ![wnnb](https://avatars.discourse-cdn.com/v4/letter/w/958977/32.png) [@wnnb](https://forums.balena.io/u/wnnb)\
**Post date:** [October 8, 2020, 12:19pm UTC](https://forums.balena.io/t/multicontainer-unable-resolve-service-names/197095/7 "2020-10-08T12:19:13Z")

</div>

Ok, I might have it wrong, but I thought that was default behaviour by docker-compose and resolved by [https://github.com/balena-io/balena-supervisor/pull/933/files](https://github.com/balena-io/balena-supervisor/pull/933/files)

But if I then understand you correctly, this does not work unless we use “networks:” ?

```auto
version: '2.1'
services:
  service-a:
    build: ./service-a
    network_mode: "host"
    networks:
      main:
        aliases:
          - service-a
    ports:
      - "80:80"

  service-b:
    build: ./service-b
    network_mode: "bridge"
    networks:
      main:
        aliases:
          - service-b

  servicec:
    build: ./service-c
    network_mode: "bridge" 
    networks:
      main:
        aliases:
          - service-c
    expose: 
      - "8080"

```

---

<div class="post-metadata">

**Author:** ![dfunckt](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dfunckt/32/56_2.png) [@dfunckt](https://forums.balena.io/u/dfunckt)\
**Post date:** [October 8, 2020, 12:42pm UTC](https://forums.balena.io/t/multicontainer-unable-resolve-service-names/197095/8 "2020-10-08T12:42:04Z")

</div>

I wasn’t aware the Supervisor adds the service name in aliases implicitly. Strip down config to the bare minimum – ie. remove network\_mode, networks, etc. – and see where that takes you.

---

<div class="post-metadata">

**Author:** ![wnnb](https://avatars.discourse-cdn.com/v4/letter/w/958977/32.png) [@wnnb](https://forums.balena.io/u/wnnb)\
**Post date:** [October 8, 2020, 1:38pm UTC](https://forums.balena.io/t/multicontainer-unable-resolve-service-names/197095/9 "2020-10-08T13:38:27Z")

</div>

That is basically where we started, first we only had “network\_mode” on one of the containers - the one that required to act at “host” mode, runnning a API.

The other containers then had nothing and resolution did not work between them.  
We added “network\_mode” in either “host” or “bridge” to all of the containers without this resolving anything.

Now on the last build, acording to your instructions we will try to add this to all of the containers and see where that takes us 🙂

```auto
    networks:
      main:
        aliases:
          - service-a

```

---

<div class="post-metadata">

**Author:** ![wnnb](https://avatars.discourse-cdn.com/v4/letter/w/958977/32.png) [@wnnb](https://forums.balena.io/u/wnnb)\
**Post date:** [October 8, 2020, 2:52pm UTC](https://forums.balena.io/t/multicontainer-unable-resolve-service-names/197095/11 "2020-10-08T14:52:09Z")

</div>

This configurations takes us nowhere, i have read over the docker-compose documentation once more and it states

> By default Compose sets up a single network for each container. Each container is automatically joining the default network which makes them reachable by both other containers on the network, and discoverable by the hostname defined in the Compose file.

I am not able to achieve this with balena, any advise on how to proceed?

---

<div class="post-metadata">

**Author:** ![shaunmulligan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/shaunmulligan/32/34_2.png) [@shaunmulligan](https://forums.balena.io/u/shaunmulligan)\
**Post date:** [October 8, 2020, 3:46pm UTC](https://forums.balena.io/t/multicontainer-unable-resolve-service-names/197095/12 "2020-10-08T15:46:52Z")

</div>

hi @wnnb . I think the `aliases` key is not supported on balena. We only support a subset of the compose fields detailed here: [https://www.balena.io/docs/reference/supervisor/docker-compose/#docker-composeyml-fields](https://www.balena.io/docs/reference/supervisor/docker-compose/#docker-composeyml-fields) .

In terms of how to proceed. I would start from our basic example here: [https://github.com/balena-io-examples/multicontainer-getting-started](https://github.com/balena-io-examples/multicontainer-getting-started) in which we have services talking to each other using the service name, via HAproxy. I would also look at removing the ` network_mode: "bridge"` as that is not needed and also I think if you have one of the services on `network_mode: "host"` that service won’t be added on the default bridge so won’t be able to easily fined the others.

---

<div class="post-metadata">

**Author:** ![wnnb](https://avatars.discourse-cdn.com/v4/letter/w/958977/32.png) [@wnnb](https://forums.balena.io/u/wnnb)\
**Post date:** [October 8, 2020, 5:05pm UTC](https://forums.balena.io/t/multicontainer-unable-resolve-service-names/197095/14 "2020-10-08T17:05:58Z")

</div>

That was it!  
Removing all “network\_mode:” and “networks” from the config, leaving only “ports:” for externally accesible ports, and using “expose:” for additional ports to be exposed between the containers only solved it 🙂

Thanks!

---

<div class="post-metadata">

**Author:** ![shaunmulligan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/shaunmulligan/32/34_2.png) [@shaunmulligan](https://forums.balena.io/u/shaunmulligan)\
**Post date:** [October 8, 2020, 5:58pm UTC](https://forums.balena.io/t/multicontainer-unable-resolve-service-names/197095/15 "2020-10-08T17:58:34Z")

</div>

Awesome, glad that worked!
