0

Im trying to automate a docker run shell script that needs to spin up an X11 app running on a docker-machine VM with virtualbox driver on OSX/mac. To get the x11 app to forward the X11 display to the desktop host i need to get the ip address of the correct vboxnet* (i assume) network interface (not the docker ip) and export that ip into the docker container.

what i am currently doing is assuming that the docker-machine VM ip is tied to the "vboxnet1" interface name and regexp'ing it out of ifconfig.

i see that the virtualbox DHCP process that spins up when i start docker-machine has a trunk name that corresponds to the interface i want - but again this seems like an assumption and i would think there is some command i could run to be certain which address it is so my docker run script will work on any machine.

/Applications/VirtualBox.app/Contents/MacOS/VBoxNetDHCP --ip-address    
192.168.99.2 --lower-ip 192.168.99.100 --mac-address XXXXXXXXXXX
  --netmask 255.255.255.0 --network HostInterfaceNetworking-vboxnet1 
--trunk-name vboxnet1 --trunk-type netadp --upper-ip 192.168.99.254

Is there a way to definitively determine which network interface to find the ip address?

4

2 回答 2

0

这个 bash 脚本似乎可以在 OSX 机器上运行:

#!/bin/bash    
CONFIG=$( ifconfig | grep -A 2 'vboxnet1')

regex="([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})"

if [[ $CONFIG =~ $regex ]]; then
      DISPLAY=${BASH_REMATCH[1]}
      DISPLAY+=":0"
fi
于 2015-09-30T02:20:29.680 回答
-1
ifconfig $(route -n get $(docker-machine ip default) | grep interface: | awk '{print $2}') | grep inet | awk '{print $2}'
于 2016-04-06T00:04:13.750 回答