Solving permission denied while trying to connect to Docker daemon socket from container in Mac OS

Mac OS is my main development platform and a while back I found myself in a Docker-ception situation — a Docker container tried to create another Docker container on my Mac OS. Oh and behold the following error:

Well, error messages are part and parcel of programming so if the code runs on the first try, I’d leave it to your imagination on what that means.

So onto the usual googling, I mean, debugging process.

Turns out the yaml compose file for the service was written on Linux/Ubuntu. But on Mac OS, there’s a socket connection issue between Docker container and the host Docker daemon.

My workaround is to spin up a socat container — a unix tool that creates two bidirectional streams between two endpoints, and use it as a relay. The lines of code in bold below are what I’ve added to the compose file to resolve the problem.

services:
awesomeapp:
image: awesomeapp
.
.
environment:
- DOCKER_HOST=tcp://socat:2375
links:
- socat
socat:
image: bpack/socat
command: TCP4-LISTEN:2375,fork,reuseaddr UNIX-
<cont on prev line>CONNECT:/var/run/docker.sock
volumes:
- /var/run/docker.sock:/var/run/docker.sock
expose:
- "2375"

Hope this helps :)

Data Scientist

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store