Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Docker for mac listen on a tcp port

Tags:

docker

macos

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?

like image 207
Michael Nelson Avatar asked Sep 01 '16 03:09

Michael Nelson


People also ask

What port does Docker listen on?

The Docker client will default to connecting to unix:///var/run/docker.sock on Linux, and tcp://127.0.0.1:2376 on Windows. For example: tcp:// -> TCP connection to 127.0. 0.1 on either port 2376 when TLS encryption is on, or port 2375 when communication is in plain text.

How do I enable expose daemon on TCP localhost 2375 without TLS on Mac?

on the Notification bar, select Settings from the context menu, and then select the Expose daemon on tcp://localhost:2375 without TLS checkbox in the General section of your system Docker settings. Docker for Mac: The recommended option when using Docker Desktop for Mac.

How do I run a Docker image locally on Mac?

Install and run Docker Desktop on MacDouble-click Docker.dmg to open the installer, then drag the Docker icon to the Applications folder. Double-click Docker.app in the Applications folder to start Docker.


2 Answers

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

like image 61
Marcello Romani Avatar answered Oct 04 '22 05:10

Marcello Romani


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.

like image 29
VonC Avatar answered Oct 04 '22 06:10

VonC