2

I try to mount a volume in docker container using nodejs app on windows. When I try this command on the cmd:

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. 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). When I use the same code on mac, it works fine. How can I fix it? thanks.

matsev
  • 32,104
  • 16
  • 121
  • 156
GalRoimi
  • 37
  • 5

1 Answers1

0

You need to escape your path delimeters - without correct escapes, binds are resolved as C:UsersUserdata:/stuff:rw (\U maps to just U, etc.).

So instead of

'Binds': ['C:\Users\User\data:/stuff:rw']

Use:

'Binds': ['C:\\Users\\User\\data:/stuff:rw']
jsalonen
  • 29,593
  • 15
  • 91
  • 109