Search code examples
macosdockertcpdocker-for-mac

how to connect to Docker via TCP on MacOS


I am a neophyte when it comes to networking issues more generally, and Docker specifically, which I'm sure will become apparent in this question.

Right now the relatively simple thing I'd like to accomplish is enabling the tcp socket on Docker for Mac (and further to that, understanding where to ping my Docker host from a client machine). I'm cheating a little bit in that I'm not describing my ultimate goal, and I know that causes the X-Y problem, but my real goal right now is to understand both Docker and networking a little better, and if I can get to the point where I had the tcp socket enabled I'll have learned something.

Here are the obstacles: This is the main documentation about enabling the tcp socket for the docker daemon. But apparently this dockerd binary does not exist on Docker for Mac.

So how do I accomplish the analogous task? This answer suggests one possibility, but one problem I have is that I don't understand what IP my docker host is at with that option (this is probably because I'm confused about networking issues).

Also, if you click the whale, there's a daemon tab that takes a JSON object. Maybe I could put the port and IP address at which I would like to listen there? But using what syntax? What is the name of the key? Where is this documented? If the answer is here I don't understand it.

Any help you could provide is appreciated!


Solution

  • See below github issue

    https://github.com/docker/for-mac/issues/1443#issuecomment-288055240

    which points to

    https://github.com/docker/for-mac/issues/1156#issuecomment-273764881

    and which indicates you can't do it as of now using config. You can do it like below

    $ socat TCP-LISTEN:2376,reuseaddr,fork,bind=127.0.0.1 UNIX-CLIENT:/var/run/docker.sock
    

    This will expose the docker socket on 2376 on your mac