Enabling docker remote API on OSX

Recently I was playing with docker API on OSX to use with Jenkins and the setup was little complicated so I thought to put all steps together in one place. Just to summarise the default tcp port for docker is 2375 (unencrypted) and 2376(encrypted) communication over tcp(although we can choose any other port).

The setup on linux is fairly straight away using systemd and a lot of help is out there however on OSX there are issues to deal with.

For security reasons , on OSX the default tcp port is not exposed and listens to socket/var/run/docker.sock .

The way I got it working was to consume docker api on your OSX.

  1. Easy way: Use socat container . This container can redirect the Docker API exposed on the unix domain socket in Linux to the port of our choice on OSX host. Most of the time you will need this if you want to just play with api. On your shell run –
>>   docker run -d -v /var/run/docker.sock:/var/run/docker.sock --name socat -p 127.0.0.1:2375:2375 bobrik/socat TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock
>>   export DOCKER_HOST=tcp://localhost:2375
>>   curl localhost:2375/images/json | jq .