9

I'm trying to get docker-java (https://github.com/docker-java/docker-java) to work with Docker for mac (https://docs.docker.com/docker-for-mac/).

How can I set the equivalent of:

DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock"

On the mac version of Docker?

4 Answers 4

16

There is a related answer which suggests a workaround using socat.

It does indeed work to expose port 2375 on the network:

socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock

Reference: Access Docker daemon Remote api on Docker for Mac

3

If you are using the last docker for mac beta, according to issue 25064:

~/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux is a git database.

Note: if ~/Library/Containers/com.docker.docker/Data/database/ does not contain com.docker.driver.amd64-linux, go to that database/ folder, and do a git reset --hard.

The daemon configuration is under etc/docker/daemon.json, which just uses the config from the Linux configuration file.

You need to change the config and then do a git commit: docker should restart automatically at that point (if not, restart it) with the new configuration.


As mentioned by the OP Michael Nelson in the comments, and detailed in "Docker for Windows" (which has sections relevant for "Docker for Mac")

The VM (Alpine-based) uses OpenRC as its init system.

The Docker init script relies on a /usr/bin/mobyconfig script.
This mobyconfig script requires the kernel to boot with a com.docker.database label specifying the location of the config file or it bails.

The mobyconfig script is able to retrieve network and insecure-registry configuration for the Docker daemon or pick up a config file from /etc/docker/daemon.json.

2
  • 4
    wow.. this impressively convoluted. These files aren't read directly after that git magic. They have another magic mobyconfig utility that reads config from /Database/branch/master/ro/com.docker.driver.amd64-linux where the files magically turns up in the VM and then the util recreates the real config files during startup :0
    – Matt
    Sep 1, 2016 at 8:40
  • 2
    This is all correct, but if I put any value into the hosts field of daemon.json then Docker refuses to start. I tried many combinations of ["unix:///var/run/docker.socket", "127.0.0.1", "fd://"] all to no avail. Sep 1, 2016 at 16:53
0

This is probably because you don't have a machine running.

eval $(docker-machine env default)

If the output is stating that no default machine, then execute,

docker-machine create default --driver virtualbox

This will create a default machine and the connection will be successful.

-2

$ docker info

HTTP Proxy: docker.for.mac.http.internal:3128

HTTPS Proxy: docker.for.mac.http.internal:3129

Registry: https://index.docker.io/v1/

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.