I'm new to Docker and trying to understand what is the best way to insert docker parent host ip into container hosts file.
I'm using the following command in my Dockerfile
RUN /sbin/ip route|awk '/default/ { print $3,"\tdockerhost" }' >> /etc/hosts
but sometimes hosts ip get change so its non relevant anymore...
The reason to do that, if you ask yourself, is that i need to access another 2 dockers containers (and link not offer this feature).
Thanks,
--add-host
option can be used when you create/run your container but since/sbin/ip
command isn't available in operating systems like OSX, we can use a more generic solution:docker run --add-host=dockerhost:`docker network inspect \ --format='{{range .IPAM.Config}}{{.Gateway}}{{end}}' bridge` [IMAGE]
The
--add-host
option is made for this. So, in yourdocker run
command, do something like: