Last active
September 11, 2019 13:28
-
-
Save fabri1983/ff900cba76d5daf38ce4506665046c7a to your computer and use it in GitHub Desktop.
Change Docker Machine IP address on Windows for Docker Tool Box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal enabledelayedexpansion | |
:: Usage: | |
:: This scripts change a docker machine's ip address created using Docker Tool Box. | |
:: NOTE: you need to run ifconfig on machine instance to know whether interface you want to modify: eth0 or eth1 | |
:: Eg for default machine: | |
:: First you need to start the default docker machine | |
:: docker-machine start default | |
:: Secondly change IP address: | |
:: dmvbf.bat default 99 100 eth1 | |
:: Finally: | |
:: docker-machine regenerate-certs default | |
:: docker-machine env default | |
:: docker-machine restart default | |
set machine=%1 | |
if "%machine%" == "" ( | |
echo dmvbf expects a machine name ^(eg default^) | |
exit /b 1 | |
) | |
set ipx=%2 | |
if "%ipx%" == "" ( | |
echo dmvbf x missing ^(for 192.168.x.y^) | |
exit /b 2 | |
) | |
set ipy=%3 | |
if "%ipy%" == "" ( | |
echo dmvbf y missing ^(for 192.168.x.y^) | |
exit /b 3 | |
) | |
set interface=%4 | |
if "%ipy%" == "" ( | |
echo dmvbf interface missing ^(eg eth1^) | |
exit /b 4 | |
) | |
echo Sending commands to docker machine %machine% via ssh | |
echo kill $(more /var/run/udhcpc.%interface%.pid) | docker-machine ssh %machine% sudo tee /var/lib/boot2docker/bootsync.sh >NUL | |
echo ifconfig %interface% 192.168.%ipx%.%ipy% netmask 255.255.255.0 broadcast 192.168.%ipx%.255 up | docker-machine ssh %machine% sudo tee -a /var/lib/boot2docker/bootsync.sh >NUL | |
echo route add default gw 0.0.0.0 | docker-machine ssh %machine% sudo tee /var/lib/boot2docker/bootsync.sh >NUL | |
docker-machine ssh %machine% "sudo cat /var/run/udhcpc.%interface%.pid | xargs sudo kill" | |
docker-machine ssh %machine% "sudo ifconfig %interface% 192.168.%ipx%.%ipy% netmask 255.255.255.0 broadcast 192.168.%ipx%.255 up" | |
:: Linux version of three first lines: | |
:: echo "kill `more /var/run/udhcpc.eth1.pid`" | docker-machine ssh default sudo tee /var/lib/boot2docker/bootsync.sh > /dev/null | |
:: echo "ifconfig eth1 192.168.99.100 netmask 255.255.255.0 broadcast 192.168.99.255 up" | docker-machine ssh default sudo tee -a /var/lib/boot2docker/bootsync.sh > /dev/null | |
:: echo "route add default gw 0.0.0.0" | docker-machine ssh default sudo tee /var/lib/boot2docker/bootsync.sh > /dev/null | |
echo Done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment