My question is how to be able to connect to the docker-machine socket, inside a docker container ?
what i want to achieve is to dockerize an api-gateway, but this api-gateway needs to communicate to the docker-machine socket, to be able to discover the running container like the following:
const machine = process.env.DOCKER_HOST
const tls = process.env.DOCKER_TLS_VERIFY
const certDir = process.env.DOCKER_CERT_PATH
if (!machine) {
throw new Error('You must set the DOCKER_HOST environment variable')
}
if (tls === 1) {
throw new Error('When using DOCKER_TLS_VERIFY=1 you must specify the property DOCKER_CERT_PATH for certificates')
}
if (!certDir) {
throw new Error('You must set the DOCKER_CERT_PATH environment variable')
}
const dockerSettings = {
protocol: 'https',
host: machine.substr(machine.indexOf(':', 0) + 3, machine.indexOf(':', 6) - 6),
port: parseInt(machine.substr(-4), 10),
checkServerIdentity: false,
ca: fs.readFileSync(certDir + '/ca.pem'),
cert: fs.readFileSync(certDir + '/cert.pem'),
key: fs.readFileSync(certDir + '/key.pem'),
version: 'v1.25'
}
This run on localhost, and has access to the env variables and has access to the docker-machine socket.
How i communicate is from the libarary dockerode
like the following
const docker = new Docker(dockerSettings)
But once i put it in a container a need to share this socket with the container to be able to execute the docker commands, this is for making a kind of docker service discovery in nodejs.