我正在尝试在另一个包含的 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 调用工作?是不是像立个flag那么简单?如果是这样,我该如何在 boot2docker 中执行此操作?
谢谢
最佳答案
例如,
docker run --rm \
-v /var/run/docker.sock:/run/docker.sock \
-v $(which docker):/bin/docker \
--privileged \
node:0.12 node my_script.js
关于node.js - 在另一个 docker 容器内运行 docker 容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28529764/