How to add a Network Domain Name to a Bridged Static IP Address

Hi,

as Topic says how can i add a Domain Name to a docker compose Network with Static ip ?

e.g.:

networks:
    dns_net:
       ipv4_address: 172.17.0.21
        
networks:
  dns_net:
    external: true

Does it work with aliases ?

I would like to reach the Address over a Domainame internal e.g http://influxdb:8086 instead of http://172.17.0.21:8086

Using container IPs directly or setting domain names pointing to container IPs is not something we usually do. You can use port mappings (ports section in compose) and add the domain names to your hosts file pointing to a loopback IP (127.0.0.1 or even 127.0.1.2 or anything you like). Or you use a reverese proxy in front of the containers but you would still need to add the domains to your hosts files the same way.

I also had an image that worked on Linux and automatically modified the hosts file, but I haven’t used it for years so I have no idea if it still works. Probably not.

Ok thats not a must, thats only a Cosmetic, so i dont need to set in the Services e.g. Telegraf the exact IP Adress.

But otherwise i set the IP once in the Service and then it works… So only Cosmetic :grinning_face:

You never mentioned whether it’s about dns resolution on your host or the network, or amongst containers within a container network.

While the last scenario is supported out of the box for user defined networks (like networks created by compose deployments), the first is out of scope of dockers responsibilities.

Usually having to rely on container ips is a sign for something that should be done differently. Even on the docker host, it is not intended to access container ports using the container ip. That’s what published ports are used for. In container to container communication, the intended solution is to put these containers in a shared network, and use the container name, service name, or network alias (if defined by user).

I have Piholev6 Docker for DNS Resolution with Unbound Docker all in the same Docker Network and all with Static IPs because i need that to communicate between some Containers.

InfluxDB and Telegraf also both in Containers and in the same Container Network as Pihole

All with Bridged Network Mode with static IPS

I cant set the Host IP to Telegraf if it communicates internal to the Container with InfluxDB

In the Telegraf config you have to specific a IP for the InfluxDB to communicate with.

Or im wrong with this ?

Usually you would connect via hostname or IP.

Docker automatically handles internal DNS within Docker networks, Docker services should be available via their compose service name or dedicated container_name. No need for fixed Docker IPs.

1 Like

Hmm ok
Do you have an example ?
In my case its not working if i set a hostname influxdb i cant connect to http://influxdb:8086

Ah ok it works, im learning :grinning_face:

I cant access it from outside only the container internal can access the hostname.

Inside a Docker network you can access services/containers by their name.

On the host directly you would usually use localhost, but need to publish the ports for them to be accessible from outside.

1 Like