问题描述
有没有办法强制docker-machine使用特定的ip创建docker vm(假设ip可用)?在
:
echoifconfig eth1 192.168.99.50 netmask 255.255.255.0 broadcast 192.168.99.255 up| docker-machine ssh prova-discovery sudo tee /var/lib/boot2docker/bootsync.sh> / dev / null
docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
test-1 - virtualbox运行tcp://192.168.99.50:2376 test-1(master)
我已更新命令:
echokill`more /var/run/udhcpc.eth1.pid`\\\
ifconfig eth1 192.168。 99.50网络掩码255.255.255.0 broadcast 192.168.99.255 up| docker-machine ssh prova-discovery sudo tee /var/lib/boot2docker/bootsync.sh> / dev / null
docker-machine regenerate-certs prova-discovery
(以您的码头机的名称替换 prova-discovery
)
这里是(Windows)脚本( dmvbf.bat
)我现在使用,基于上面的内容:
@echo off
setlocal enabledelayedexpansion
set machine =%1
如果%machine%= =(
echo dmvbf期望机器名称
exit / b 1
)
set ipx =%2
如果%ipx%== (
echo dmvbf x missing ^(for 192.168.xy ^)
exit / b 2
)
set ipy =%3
如果%ipy%= =(
echo dmvbf y missing ^(for 192.168.xy ^)
exit / b 3
)
echo kill $(more / var / run /udhcpc.eth1。 pid)| docker-machine ssh%machine%sudo tee /var/lib/boot2docker/bootsync.sh> NUL
echo ifconfig eth1 192.168。%ipx%。%ipy%netmask 255.255.255.0 broadcast 192.168。%ipx%.255 | | docker-machine ssh%machine%sudo tee -a /var/lib/boot2docker/bootsync.sh> NUL
docker-machine ssh%machine%sudo cat /var/run/udhcpc.eth1 .pid | xargs sudo kill
docker-machine ssh%machine%sudo ifconfig eth1 192.168。%ipx%。%ipy%netmask 255.255.255.0 broadcast 192.168。%ipx%.255 up
我启动vm( docker-machine start< machine-name> / code>),然后:
dmvbf< machine-name> 99 101
我只做一次。
在下一个 docker-machine start< machine-name>
中,IP将为192.168.99.101。
Is there a way to force docker-machine to create the docker vm with a specific ip (assuming that ip is available)?
That is actively requested in docker/machine
issue 1709
The current workaround:
echo "ifconfig eth1 192.168.99.50 netmask 255.255.255.0 broadcast 192.168.99.255 up" | docker-machine ssh prova-discovery sudo tee /var/lib/boot2docker/bootsync.sh > /dev/null
docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
test-1 - virtualbox Running tcp://192.168.99.50:2376 test-1 (master)
Michele Tedeschi (micheletedeschi
) adds
I've updated the commands with:
echo "kill `more /var/run/udhcpc.eth1.pid`\nifconfig eth1 192.168.99.50 netmask 255.255.255.0 broadcast 192.168.99.255 up" | docker-machine ssh prova-discovery sudo tee /var/lib/boot2docker/bootsync.sh > /dev/null
docker-machine regenerate-certs prova-discovery
(replace prova-discovery
by the name of your docker-machine)
Here is the (Windows) script (dmvbf.bat
) I now use, based on what is above:
@echo off
setlocal enabledelayedexpansion
set machine=%1
if "%machine%" == "" (
echo dmvbf expects a machine name
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
)
echo kill $(more /var/run/udhcpc.eth1.pid) | docker-machine ssh %machine% sudo tee /var/lib/boot2docker/bootsync.sh >NUL
echo ifconfig eth1 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
docker-machine ssh %machine% "sudo cat /var/run/udhcpc.eth1.pid | xargs sudo kill"
docker-machine ssh %machine% "sudo ifconfig eth1 192.168.%ipx%.%ipy% netmask 255.255.255.0 broadcast 192.168.%ipx%.255 up"
I start the vm (docker-machine start <machine-name>
), and then:
dmvbf <machine-name> 99 101
I do that only once.
At the next docker-machine start <machine-name>
, the IP will be 192.168.99.101.
这篇关于有没有办法强制停泊机使用特定的ip创建vm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!