Docker Community Forums

Share and learn in the Docker community.

Connecting via unix-socket to the docker-daemon


(Winfle) #1

Hey, guys.
How could I connect to the docker-daemon via unix socket, located unix:///var/run/docker.sock ?
I need this for PHP Storm integration, but when I trying to do it I’m getting the follow:
**… Could not initialize class **
How could I solve this problem? Or maybe this feature doesn’t work yet in Docker for mac?

(David Maze) #2

Make sure the DOCKER_HOST environment variable is unset, and the standard docker commands will talk to it there. Note that the path is slightly different on the Mac beta than on Linux; the socket is in /private/var/run/docker.sock.

Could you give more context, like a code sample that demonstrates the issue?

(Tobias Gesellchen) #3

You’re probably running into an issue with the underlying docker-java library used by PHPStorm. See for details.

A workaround is to expose the unix socket via HTTP:

docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p bobrik/socat TCP-LISTEN:1234,fork UNIX-CONNECT:/var/run/docker.sock

Then you need to tell your PHPStorm to use the Docker host at localhost:1234. On your shell that’s possible via:

export DOCKER_HOST=tcp://localhost:1234

(Nils Meder) #4

I’m having the same problem trying to start a Docker container inside my Docker container (Jenkins).

Docker Compose:

  build: ~/tmp
  privileged: true
    - 8080:8080
    - 50000:50000
    - ~/tmp/data:/mnt/data
    - /private/var/run/docker.sock:/var/run/docker.sock
    - ~/.docker/config.json:/var/jenkins_home/.docker/config.json

/private/var/run/docker.sock on my macOS host is a link to ~/Library/Containers/com.docker.docker/Data/s60, there is no difference if mounting the link or the s60 itself.

Inside the container, I always get Cannot connect to the Docker daemon. Is the docker daemon running on this host?, the DOCKER_HOST is not set.

DiagnoseID: 5F317F57-C34D-47A6-BA0B-E543BBA1A7C1

Is there any way to achieve DinD with Docker for Mac?