docker / compose

Define and run multi-container applications with Docker
https://docs.docker.com/compose/
Apache License 2.0
33.59k stars 5.19k forks source link

Add container name with current ip to /etc/hosts #682

Closed mhubig closed 9 years ago

mhubig commented 9 years ago

Currently when I start a container with fig the /etc/hosts file typically looks like this (with 172.17.0.61 as the IP-Address of the current container):

172.17.0.61 b2e3a12debf4
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.59 database
172.17.0.59 database_1
172.17.0.59 atlassian_database_1

It would be nice if there where the same predictable entries for the current container like the ones for the linked database container ... e.g.:

172.17.0.61 b2e3a12debf4
172.17.0.61     crowd
172.17.0.61     crowd_1
172.17.0.61     atlassian_crowd_
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.59 database
172.17.0.59 database_1
172.17.0.59 atlassian_database_1

EDIT: And maybe also set the hostname to the service name instead of the container id ...

david-guenault commented 9 years ago

this is already implemented

use hostname: yourhostname in your fig.yml like this :

c1: image: dguenault/shinken-central:1.4.4 name: c1 hostname: c1

this will result into your container in :

-bash-4.1# hostname c1 -bash-4.1# cat /etc/hosts 172.17.0.21 c1 ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet

mhubig commented 9 years ago

Thanks missed that one!

EDIT: I use https://github.com/crosbymichael/skydns and https://github.com/crosbymichael/skydock now ...

david-guenault commented 9 years ago

so am i but the question was really centered on hostname so .....