# DNS resolver in container

**URL:** <https://forums.balena.io/t/dns-resolver-in-container/341650>\
**Category:** Project help\
**Tags:** network\
**Created:** [July 27, 2021, 3:58pm UTC](https://forums.balena.io/t/dns-resolver-in-container/341650 "2021-07-27T15:58:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ttmetro](https://avatars.discourse-cdn.com/v4/letter/t/779978/32.png) [@ttmetro](https://forums.balena.io/u/ttmetro)\
**Post date:** [July 27, 2021, 3:58pm UTC](https://forums.balena.io/t/dns-resolver-in-container/341650/1 "2021-07-27T15:58:26Z")

</div>

I’d like use dns to lookup the ip address of other applications on the same network.

This works fine from the host (e.g. ping sever.local),

```auto
$ ping server.local
PING server.local (172.17.0.1): 56 data bytes
64 bytes from 172.17.0.1: seq=0 ttl=64 time=0.215 ms

```

but fails from my containers.

```auto
$ ping server.local
ping: server.local: Name or service not known

```

Is there a way to configure containers to use the same dns resolution as the host?

---

<div class="post-metadata">

**Author:** ![tmigone](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tmigone/32/2814_2.png) [@tmigone](https://forums.balena.io/u/tmigone)\
**Post date:** [July 27, 2021, 5:28pm UTC](https://forums.balena.io/t/dns-resolver-in-container/341650/3 "2021-07-27T17:28:37Z")

</div>

Hello there, you’ll need to install avahi with mdns in order to resolve .local domains from a container. We’ve got a sample project you can check out that shows you how to do it: [GitHub - balena-io-examples/balena-avahi: mDNS/.local resolution with Avahi within a container](https://github.com/balena-io-examples/balena-avahi)

---

<div class="post-metadata">

**Author:** ![ttmetro](https://avatars.discourse-cdn.com/v4/letter/t/779978/32.png) [@ttmetro](https://forums.balena.io/u/ttmetro)\
**Post date:** [July 27, 2021, 5:56pm UTC](https://forums.balena.io/t/dns-resolver-in-container/341650/5 "2021-07-27T17:56:41Z")

</div>

This sets a different `ENTRYPOINT` - won’t that break `UDEV`?  
Or can I somehow run both entrypoints?

Thanks for the quick response!

---

<div class="post-metadata">

**Author:** ![tmigone](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tmigone/32/2814_2.png) [@tmigone](https://forums.balena.io/u/tmigone)\
**Post date:** [July 27, 2021, 6:05pm UTC](https://forums.balena.io/t/dns-resolver-in-container/341650/6 "2021-07-27T18:05:44Z")

</div>

Good catch, that will break udev indeed. You can remedy that by invoking the base image’s entry script on the entry.sh script. Here is an example where i did that: [audio/entry.sh at master · balenablocks/audio · GitHub](https://github.com/balenablocks/audio/blob/master/entry.sh#L4-L5)

---

<div class="post-metadata">

**Author:** ![ttmetro](https://avatars.discourse-cdn.com/v4/letter/t/779978/32.png) [@ttmetro](https://forums.balena.io/u/ttmetro)\
**Post date:** [July 27, 2021, 6:58pm UTC](https://forums.balena.io/t/dns-resolver-in-container/341650/7 "2021-07-27T18:58:12Z")

</div>

Now the container is stuck in “starting service …”.

The output from

```auto
echo -e "${GREEN}Systemd init system enabled."

```

does not show up in the log.

Also the `CMD` instruction does not seem to be called.

---

<div class="post-metadata">

**Author:** ![pdcastro](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/pdcastro/32/1264_2.png) [@pdcastro](https://forums.balena.io/u/pdcastro)\
**Post date:** [August 9, 2021, 4:04pm UTC](https://forums.balena.io/t/dns-resolver-in-container/341650/9 "2021-08-09T16:04:25Z")

</div>

> Is there a way to configure containers to use the same dns resolution as the host?
> 
> > you’ll need to install avahi with mdns in order to resolve .local domains from a container […]

By the way, if `server.local` is some other device or machine on the local network, I think you would also need to configure host networking ([`network_mode: host`](https://docs.docker.com/compose/compose-file/compose-file-v2/#network_mode) in the docker-compose.yml file). Not sure if the container would need to be privileged as well ([privileged: true](https://docs.docker.com/compose/compose-file/compose-file-v2/#cpu-and-other-resources)).

> Now the container is stuck in “starting service …”.  
> Also the `CMD` instruction does not seem to be called.

Try debugging what is actually being executed when the container starts. An ENTRYPOINT instruction is optional and interacts with a CMD instruction in certain ways. Check the documentation for both: [CMD](https://docs.docker.com/engine/reference/builder/#cmd) and [ENTRYPOINT](https://docs.docker.com/engine/reference/builder/#entrypoint). Note that the ENTRYPOINT and CMD instructions of a base image will be “inherited”. If you need to override them and you would rather use just CMD to make things simpler, a trick is to set ENTRYPOINT to `'/usr/bin/env'` as in [this StackOverflow post](https://stackoverflow.com/a/41207569/10226634).

> Or can I somehow run both entrypoints?

Yes, in a way – by setting up your own entrypoint script (single entrypoint, say `'/usr/src/app/entry.sh'`) and editing your script so that it calls any other script you like (the other entrypoint, e.g. `'/usr/bin/entry.sh'`). By the way, the entrypoint does not need to be a shell script: it can be any executable written in your chosen programming language.
