Using Dockerode On macOS
Trying to use the awesome Dockerode on my dev machine to automate a build. I keep getting the following error:
{ Error: Parse Error
at Socket.socketOnData (_http_client.js:439:20)
at Socket.emit (events.js:159:13)
at addChunk (_stream_readable.js:265:12)
at readableAddChunk (_stream_readable.js:252:11)
at Socket.Readable.push (_stream_readable.js:209:10)
at TCP.onread (net.js:598:20) bytesParsed: 0, code: 'HPE_INVALID_CONSTANT' }
The issue is that we need to to load the TLS certs into Dockerode and use it for talking to the API. The following code should work:
docker = new Docker({
protocol: 'https',
host: '192.168.59.103',
port: process.env.DOCKER_PORT || 2375,
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')
});
If you are using docker-machine then you cat get the value of DOCKER_CERT_PATH
by printing the env for your machine:
$ docker-machine env dev
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/user/.docker/machine/machines/dev"
export DOCKER_MACHINE_NAME="dev"
# Run this command to configure your shell:
# eval $(docker-machine env dev)