Dockerode: socket initialization not working in windows.

Created on 26 Aug 2016  路  11Comments  路  Source: apocas/dockerode

Integrating this library, docker socker command works in mac but not on windows.

var socket = process.env.DOCKER_SOCKET || '/var/run/docker.sock';
var stats = fs.statSync(socket);

It gives following error
fs.js:992 Uncaught Error: ENOENT: no such file or directory, stat 'C:\var\rundocker.sock'

Most helpful comment

Using the latest Docker for Windows release I've managed to get it working through a pipe using the socket configuration.

socketPath: '//./pipe/docker_engine'

Had trouble finding this as it was not documented.

All 11 comments

You'll most likely need to use TCP to get dockerode working on Windows.
Follow https://msdn.microsoft.com/en-au/virtualization/windowscontainers/docker/configure_docker_daemon.
In particular you'll want to add something like "hosts": ["0.0.0.0:2375", "npipe://"] to your Docker config and connect via new Dockerode({ port: 2375 }) instead.

If you do figure out how to get the socketPath working, I'd be interested to see it!

@dhavalyours what version of windows are you running, and do you have the Windows subsystem for Linux enabled?

Hi,
I m running windows 7. i have installed docker through virtual machine.

Where are you trying to use dockerode form? Windows or Linux?

You will most likely need to enable TCP and use similar instructions to what I said earlier.

Hi,

i tried initializing through following code i am getting container undefined.

var docker = new Docker({
protocol: 'tcp',
host: '0.0.0.0',
port: 2376
});

docker.listContainers(function (err, containers) {
    console.log("cp112343   "+err);
    console.log("container is  "+containers);

});

You'll need to configure docker to accept connections over TCP. On my phone at the moment so I can't dig up a link. You're looking to set something like DOCKER_OPTS="-h tcp://0.0.0.0:2375 -h unix:///var/run/docker.sock" in /etc/default/docker

On Windows, TCP is the way to go regarding this.

Using the latest Docker for Windows release I've managed to get it working through a pipe using the socket configuration.

socketPath: '//./pipe/docker_engine'

Had trouble finding this as it was not documented.

By @apocas :

On Windows, TCP is the way to go regarding this.

How am I supposed to use TCP, then ? I tried setting protocol to 'TCP' but it doesn't seem to exist.
Do I have to go inside my VM to change stuff ?

@apocas could you add something to check if the OS is Windows or *NIX and change the default from /var/run/docker.sock to use TCP since the default shouldn't just work if you're using *NIX.

I managed to make it work on Windows 7 using Docker Toolbox.
I post the bit of code used in case someone needs it later :

import Docker from 'dockerode';
import fs from 'fs';

const isWin = process.platform === 'win32';
let docker;

if (isWin) {
    const BASE_PATH = "C:/Users/<username>/.docker/machine/machines/default/";
    docker = new Docker({
        host: '192.168.99.100',
        protocol: 'https',
        ca: fs.readFileSync(BASE_PATH + 'ca.pem'),
        cert: fs.readFileSync(BASE_PATH + 'cert.pem'),
        key: fs.readFileSync(BASE_PATH + 'key.pem'),
        port: 2376
    });
}

The host and port were obtained with the command docker-machine url default which returned tcp://192.168.99.100:2376.
I just ignored the tcp:// part and forced the protocol to be 'https'.
Finally, I gave the paths to the required certificates and the connection worked as expected.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

knight42 picture knight42  路  7Comments

stanleygu picture stanleygu  路  4Comments

mhemrg picture mhemrg  路  4Comments

controversial picture controversial  路  3Comments

tkarls picture tkarls  路  6Comments