How to assign a docker-machine host a static ip address


Boot2docker uses DHCP by default. Most solutions I found simply assign a static address and neglect to disable DHCP. Which led to the machine simply changing its ip address after some time.

This command line should take care of that:

cat <<EOF | docker-machine ssh docker-host sudo tee /var/lib/boot2docker/bootsync.sh > /dev/null
kill `more /var/run/udhcpc.eth0.pid`
ifconfig eth0 10.0.0.10 netmask 255.255.255.0 broadcast 10.0.0.255 up
ip route add default via 10.0.0.1
EOF

After creating that file on the host restart it and regenerate the client certificates:

docker-machine restart docker-host
docker-machine env docker-host
docker-machine regenerate-certs docker-host

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.