在Mac OS X上的Docker中启用远程API(boot2docker) [英] Enabling Remote API in Docker on Mac OS X (boot2docker)

查看:595
本文介绍了在Mac OS X上的Docker中启用远程API(boot2docker)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用boot2docker时,似乎无法确定如何启用远程API。我试图使用dockerode如下:

  Docker = require('dockerode')
docker = new Docker socketPath:/var/run/docker.sock)

container = docker.getContainer('< my_container_id>')

container.inspect(err,data) - >
调试数据

数据为空,尽管存在ID为'的容器。我怀疑这是因为在OS X主机上没有/var/run/docker.sock,而且我需要使用以下内容:

  var docker2 = new Docker({host:'http://192.168.1.10',port:3000}); 

...但无法确定如何在VirtualBox VM中配置boot2docker或docker以启用通过http或tcp访问。

解决方案

由Dock2Docker配置的Docker支持从主机端口2375远程访问默认情况下为OSX机器这是当它告诉你做导出DOWER_HOST = tcp://192.168.59.103:2375



如果要从另一台机器访问端口,则需要配置VirtualBox网络以将流量路由到该端口。这可以通过以下命令进行端口转发:

  VBoxManage modifyvmboot2docker-vm--natpf1guestssh,tcp, ,2375,,2375

然后在您的新Docker中使用的地址代码是Mac的IP地址。



您也可以在VirtualBox GUI中配置boot2docker-vm / settings / network / advanced /端口转发。



请参阅 VirtualBox文档



请注意,如这里,这样现在可以让任何拥有IP访问您机器的人员来控制Docker的安装,这可能是一个安全问题。 p>

I can't seem to figure out how to enable the remote API when using boot2docker. I am trying to use dockerode as follows:

Docker = require('dockerode')
docker = new Docker(socketPath: "/var/run/docker.sock")

container = docker.getContainer('<my_container_id>')

container.inspect (err, data) ->
  debug data

Data is null, despite there being a container with the id ''. I suspect this is because there is no /var/run/docker.sock on the OS X host, and that I would need to use something like:

var docker2 = new Docker({host: 'http://192.168.1.10', port: 3000});

... but can't figure out how to configure boot2docker or docker in the VirtualBox VM to enable access via http or tcp.

解决方案

Docker, as configured by Boot2Docker, supports remote access on port 2375 from the host OSX machine by default; this is what is set up when it tells you to do export DOCKER_HOST=tcp://192.168.59.103:2375

If you want to access the port from another machine you need to configure VirtualBox networking to route traffic to that port. This could be done by port forwarding with this command:

VBoxManage modifyvm "boot2docker-vm" --natpf1 "guestssh,tcp,,2375,,2375"

Then the address to use in your new Docker code is the IP address of your Mac.

You can also configure this in the VirtualBox GUI under boot2docker-vm/settings/network/advanced/port forwarding.

See VirtualBox docs.

Note, as described here that this now allows anyone with IP access to your machine to control your Docker installation, which may be a security concern.

这篇关于在Mac OS X上的Docker中启用远程API(boot2docker)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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