[英]Mount a volume in docker using nodejs on windows
I try to mount a volume in docker container using nodejs app on windows. 我尝试在windows上使用nodejs app在docker容器中安装一个卷。 When I try this command on the cmd:
当我在cmd上尝试此命令时:
docker run -it -v C:\\Users\\User\\data:/stuff:rw ubuntu bash
docker run -it -v C:\\ Users \\ User \\ data:/ stuff:rw ubuntu bash
it works and the container contains the volume. 它工作,容器包含卷。 But if I try to do this using nodejs (dockerode module), it does not work.
但是如果我尝试使用nodejs(dockerode模块)来做这件事,它就不起作用了。 My code:
我的代码:
var dockerode = require('dockerode');
var docker = new dockerode();
var stream = require('stream');
docker.createContainer({
Image: 'ubuntu',
Cmd: ['ls', 'stuff'],
'Volumes': {
'/stuff': {}
},
'Binds': ['C:\Users\User\data:/stuff:rw']
}, function(err, container) {
container.attach({
stream: true,
stdout: true,
stderr: true,
tty: true,
'Binds': ['C:\Users\User\data:/stuff:rw']
}, function(err, stream) {
stream.pipe(process.stdout);
container.start({
'Binds': ['C:\Users\User\data:/stuff:rw']
}, function(err, data) {
console.log(data);
});
});
});
The problem is that it prints nothing (the stuff directory is empty). 问题是它什么都不打印(stuff目录为空)。 When I use the same code on mac, it works fine.
当我在mac上使用相同的代码时,它工作正常。 How can I fix it?
我该如何解决? thanks.
谢谢。
You need to escape your path delimeters - without correct escapes, binds are resolved as C:UsersUserdata:/stuff:rw
( \\U
maps to just U
, etc.). 你需要转义你的路径分隔符 - 没有正确的转义,绑定被解析为
C:UsersUserdata:/stuff:rw
( \\U
映射到U
,等等)。
So instead of 而不是
'Binds': ['C:\Users\User\data:/stuff:rw']
Use: 采用:
'Binds': ['C:\\Users\\User\\data:/stuff:rw']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.