DNS resolver in container

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),

$ 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.

$ 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?

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

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

Thanks for the quick response!

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

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

The output from

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

does not show up in the log.

Also the CMD instruction does not seem to be called.

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 in the docker-compose.yml file). Not sure if the container would need to be privileged as well (privileged: true).

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 and 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.

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.