如何使用docker-machine和VirtualBox创建具有特定URL的docker机器? [英] How do I create a docker machine with a specific URL using docker-machine and VirtualBox?

查看:557
本文介绍了如何使用docker-machine和VirtualBox创建具有特定URL的docker机器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用VirtualBox驱动程序创建一个Docker实例,但是我无法弄清楚如何指定URL。



创建命令:

  docker -machine create --driver virtualbox myBox 

docker-machine ls: / p>

  NAME ACTIVE DRIVER STATE URL SWARM 
myBox * virtualbox运行tcp://192.168.99.100:2376

我希望网址是一个特定的网址。如何强制Docker实例使用特定的URL(例如:192.168.99.113)?



详细信息: Mac 10.10。 5使用Docker Toolbox



更新



我尝试使用 -virtualbox-hostonly-cidr 命令设置docker机器的IP范围;我指定了一个IP地址范围(192.168.99.113/32),但创建的机器的IP为192.168.99.100,这在我提供的范围之外。



是否有可能设置具有特定IP地址的码头机?

解决方案

我们有一段时间也有同样的问题之前,尝试在docker机器中更改默认的docker IP,我们发现只有两种方法,如何做。


  1. 你可以调用docker机器的创建命令以使用标志创建您的Docker实例



    - virtualbox-hostonly-cidr192.168.99.1/24



    此标志设置一系列地址,可以为Docker实例设置。无法保证,您将获得所需的地址


  2. 您可以更改虚拟机的网络设置,为其保留NAT和端口转发功能,使您的Docker实例运行它被安装在主机操作系统上。


当然,第一个是标准方法,似乎更为可取。但是在某些情况下,第二个可能是有用的。



更新:
有一个打开的功能请求,用于为docker机器指定静态IP。所以,不幸的是现在不可能做到这一点。只有 - virtualbox-hostonly-cidr 属性,但是您必须在29下提供CIDR前缀才能使其工作(测试为Win版本)。或者查看此评论,在哪里显示,您可以如何通过配置虚拟框来做OS X,如:

  $ VBoxManage dhcpserver修改--ifname vboxnet0 --disable 
$ VBoxManage dhcpserver修改--ifname vboxnet0 --ip 192.168.59.3 --netmask 255.255.255.0 --lowerip 192.168.59.103 --upperip 192.168.59.203
$ VBoxManage dhcpserver修改--ifname vboxnet0 --enable
$ docker-machine create --drivervirtualbox--virtualbox-cpu-count-1--virtualbox-disk-size30000--virtualbox-memory2560--virtualbox-hostonly-cidr 192.168.59.3/24dev


I can create a Docker instance with the VirtualBox driver, but I cannot figure out how to specify the URL.

Create Command:

docker-machine create --driver virtualbox myBox

docker-machine ls:

NAME      ACTIVE   DRIVER       STATE     URL                         SWARM
myBox     *        virtualbox   Running   tcp://192.168.99.100:2376   

I want the URL to be a specific URL. How can I force the Docker instance to use a specific URL (ex: 192.168.99.113)?

Details: Mac 10.10.5 using Docker Toolbox

Update

I tried using the --virtualbox-hostonly-cidr command to set the IP range for the docker machine; I specified a range of one IP address ("192.168.99.113/32"), but the machine created had an IP of 192.168.99.100, which is outside of the range I provided.

Is it even possible to set a docker machine with specific IP address?

解决方案

We had the same problem some time ago, trying to change default docker IP in docker machine and we found only 2 ways, how to do it.

  1. You can call a create command of docker machine to create your Docker instance with flag

    --virtualbox-hostonly-cidr "192.168.99.1/24"

    This flag set a range of addresses, which could be set for a Docker instance. No guarantee, you get the address you want

  2. You can change network settings of virtual machine, leaving NAT and port forwarding for it, making your Docker instance running like it was installed on Host OS.

Of course, the first one is standard approach and seems to be preferable. But in some cases, the second could be usefull too.

Update: There is an open feature request for specifying a static IP for docker machine. So, unfortunately it's not possible to do it right now. Only --virtualbox-hostonly-cidr property, but you have to provide a CIDR Prefix below 29 to make it works (tested for Win version). Or take a look at this comment, where is shown, how you can do it for OS X by configuring Virtual Box, like:

$ VBoxManage dhcpserver modify --ifname vboxnet0 --disable
$ VBoxManage dhcpserver modify --ifname vboxnet0 --ip 192.168.59.3 --netmask 255.255.255.0 --lowerip 192.168.59.103 --upperip 192.168.59.203
$ VBoxManage dhcpserver modify --ifname vboxnet0 --enable
$ docker-machine create --driver "virtualbox" --virtualbox-cpu-count "-1" --virtualbox-disk-size "30000" --virtualbox-memory "2560" --virtualbox-hostonly-cidr "192.168.59.3/24" dev

这篇关于如何使用docker-machine和VirtualBox创建具有特定URL的docker机器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆