I’m toying with the new network feature from docker 1.9 and I’m wondering how /etc/hosts is managed now. Here’s my use case :
I create a bridge network with
I tried your attempt in single host …
you can try to find the corresponding docker driver like "docker network ls"
Im seeing all containers entries are in docker network inspect < network id >
Also you can see hostconfig.json for container mapped with related network… im able to see host file entry in each containers… ( /etc/hosts ) But i used the option --name in docker run … instead of -h . Can you give a try and let me know if you need help
Indeed I can see /etc/hosts entries for containers in the same network when I use the --name option, but the container’s own name does not appear in it’s /etc/hosts file, I have to add a -h to have container’s hostname entrie.
The drawback I see when using --name vs -h option is that I won’t be able to use the same hostname for multiple containers, even if there are in different networks.
Also there is the --mac-address option, now it applies to the docker run command, but wouldn’t it be better to set the mac address when calling the docker network connect command ?
And the same for hostnames, if one wants to have containers in multiple networks, and have different hostnames for each attached interface ?
Something like : docker network connect --hostname containerAbrA --mac-address aa:bb:cc:dd:ee:ff brA 3c08024a0547 docker network connect --hostname containerAbrB --mac-address aa:bb:cc:dd:ee:ff brB 3c08024a0547