【发布时间】:2015-02-16 20:24:33
【问题描述】:
我正在尝试在另一个包含的 docker 环境中创建一个包含的 docker 环境,并通过 NodeJS 的 exec 函数调用它。
我已经阅读了 Docker 文档,据我所知,这是通过在启动容器时传递 --privileged 标志来实现的。
当我在 Mac 上开发时,我安装了 boot2docker 以使 docker 正常工作,所以我不确定如何设置这个 --privileged 标志。
这是我目前写的代码:
var st = 'docker run virtual_machine ls'
//log the statement in console (test)
console.log(st);
//execute the Docker command
child = exec(st,
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
但这是我得到的输出(错误):
stdout:
stderr: time="2015-02-15T18:27:15Z" level="fatal" msg="Post http:///var/run/docker.sock/v1.17/containers/create: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?"
exec error: Error: Command failed: time="2015-02-15T18:27:15Z" level="fatal" msg="Post http:///var/run/docker.sock/v1.17/containers/create: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?"
我怎样才能使这个 exec 调用工作?是不是像设置一个标志那么简单?如果是这样,我该如何在 boot2docker 中执行此操作?
谢谢
【问题讨论】:
-
docker CLI 只是一个 API 客户端,我建议使用 github.com/apocas/dockerode 在从节点使用 docker 时使用它。
-
查看您的错误,您要么在没有将 docker 配置到正确 API 端点的情况下从 OSX 运行(/var/run/docker.sock 是默认值),要么是在容器中运行没有安装 docker。
-
您是想在该容器内启动一个额外的 Docker(包括其守护进程),还是联系现有的 Docker 守护进程来启动另一个容器?
标签: node.js unix exec docker boot2docker