I have Docker set up and running on one of my servers and can connect to it remotely like this:
docker --tlsverify -H tcp://web2.webcom.dk:4243 images
I used this and this to get it set up.
What I would like to do is to be able to connect to it via Node.js and have tried doing so with dockerode which to me seems to be the best option.
Here's my code:
Docker = require 'dockerode'
docker = new Docker
host: 'tcp://web2.webcom.dk'
port: 4243
tls: true
tlscacert: '/Users/jacob/.docker/ca.pem'
tlscert: '/Users/jacob/.docker/cert.pem'
tlskey: '/Users/jacob/.docker/key.pem'
tlsverify: true
container = docker.getContainer '826544226fdc'
container.start (err, data) ->
return console.error err if err?
console.log data
That doesn't work though, as I get this error:
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
Any ideas?
UPDATE
This works locally:
Docker = require 'dockerode'
docker = new Docker
host: '192.168.59.103'
port: 2375
socketPath: false
docker.run 'ubuntu', ['bash', '-c', 'uname -a'], process.stdout, (err, data, container) ->
return console.error err if err?
But if I use my remote hosts IP and port I get this:
{ [Error: Parse Error] bytesParsed: 0, code: 'HPE_INVALID_CONSTANT' }
How can I connect to my remote host?
This is a HTTP PARSER ERROR
, because your dockerd speeks HTTPS and you are using HTTP to connecting it.
If you use tls, you must set the prococol field to https
. here is my config:
docker: {
host: '192.168.59.103'
port: 2376
protocol: 'https'
ca: fs.readFileSync(process.env.DOCKER_CERT_PATH + '/ca.pem')
cert: fs.readFileSync(process.env.DOCKER_CERT_PATH + '/cert.pem')
key: fs.readFileSync(process.env.DOCKER_CERT_PATH + '/key.pem')
}