I'm using this code to inject the docker host ip into my container. It seems to work but I'm not sure exactly what ip route list
does and if this will work on other environments and if the ip param will always be 9th.
docker_host_ip=$(ip route list | grep docker0 | awk '{print $9}')
docker_compose="
version: '3.5'
services:
app:
extra_hosts:
- dockerhost:$docker_host_ip
"
echo "$docker_compose" | docker-compose \
-f docker-compose.yml \
-f /dev/stdin \
up