I am executing following code to get list of all container using npm dockerode on Ubuntu 14.04 machine. Docker container are running properly.
var Docker = require('dockerode');
var docker = new Docker({socketPath: '/var/run/docker.sock'});
docker.listContainers({all: true}, function(err, containers) {
console.log('err ' + err);
console.log('ALL: ' + containers);
});
But getting
Error connect EACCES /var/run/docker.sock
thanks in advance.
This happens because you don't have sufficient permissions to access Docker. There are two solutions:
Run the command with sudo. (not recommended)
Add current user to the docker
group using this command:
$ sudo usermod -aG docker $USER
$ newgrp docker
Logout and log back in once you run this command and try running your code again. (recommended)