[英]Running a docker container inside another docker container?
I'm trying to create a contained docker environment inside another contained docker environment and call it through NodeJS's exec
function. 我正在尝试在另一个包含的docker环境中创建一个包含的docker环境,并通过NodeJS的
exec
函数调用它。
I've read through the Docker docs and as far as I can see, this is achieved by passing the --privileged
flag when starting a container. 我已经阅读了Docker文档,据我所知,这是通过在启动容器时传递
--privileged
标志实现的。
As I'm developing on a mac, I have boot2docker installed to make docker work correctly, so I'm not sure exactly how to set this --privileged
flag. 当我在Mac上进行开发时,我安装了boot2docker以使docker正常工作,因此我不确定如何设置此
--privileged
标志。
This is the code I've written so far: 这是我到目前为止编写的代码:
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);
}
});
But this is the output (error) I'm getting: 但这是我得到的输出(错误):
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?"
How can I make this exec call work? 如何使此exec调用正常工作? Is it as simple as setting a flag?
像设置标志一样简单吗? If so, how do I do this within boot2docker?
如果是这样,如何在boot2docker中执行此操作?
Thanks 谢谢
The --privileged
flag would normally be used when you run your docker container that is running your NodeJS code above, not when starting your new container that does the ls
. --privileged
标志通常在您运行上面运行NodeJS代码的--privileged
容器时使用,而不是在启动执行ls
新容器时使用。 However, you shouldn't have to use --privileged
in this case since your new container doesn't need it. 但是,在这种情况下,您不必使用
--privileged
,因为您的新容器不需要它。 You're probably just missing the docker socket bind mount when running your NodeJS container: 运行NodeJS容器时,您可能只是缺少docker socket绑定安装:
docker run --name nodeJS -v /var/run/docker.sock:/var/run/docker.sock ...
For example, 例如,
docker run --rm \
-v /var/run/docker.sock:/run/docker.sock \
-v $(which docker):/bin/docker \
--privileged \
node:0.12 node my_script.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.