Docker SDK for Golang can't connect to daemon inside overlay network

378 Views Asked by At

I have a docker swarm, and a container inside of an overlay network on that swarm. The container has an app written in golang that interacts with the Docker API by creating a container and starting it. When I run my golang app on the host machine, everything runs perfect and it creates and runs the container without issue. However when I put the app into the container and run it in my overlay network, it no longer can reach the API.

I'm assuming this has something to do with networking, but the idea of my project is that there are multiple services, each with their own networks, that can create, launch, and remove containers they see fit. NOT running the SDK in an app outside of the overlay networks unfortunately is not an option at this time.

Error: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

1

There are 1 best solutions below

0
On BEST ANSWER

Your app is trying to access the Docker socket, but this is not accessible by default in the container.

You can mount it as a volume from the host: -v /var/run/docker.sock:/var/run/docker.sock