apocas / docker-modem

Docker Remote API network stack driver.
Apache License 2.0
234 stars 112 forks source link

Use the new Mac Docker socket default path, if present #156

Closed pimterry closed 1 year ago

pimterry commented 1 year ago

In recent Docker Desktop versions on Mac, the socket is moved to the user directory.

As a fallback, there's an optional setting to mount that at /var/run/docker.sock at login, but I'm sure many users won't enable this and so Dockerode will fail to work for them unless DOCKER_HOST is set manually.

Some discussion here: https://github.com/docker/for-mac/issues/6529 (this was released in Docker Desktop 4.13, reverted in 4.13.1, and then released for good in 4.18) More info: https://docs.docker.com/desktop/mac/permission-requirements/

I think this is simple to fix: on Mac, if /Users/<user>/.docker/run/docker.sock exists, then that should be used as the default.

This requires a small refactor, since it requires an FS operation and defaultOpts and the Modem constructor are synchronous, but this could be done by accepting a promise as an socketPath option, and waiting for that to resolve during dial (which is async) in that case.

Would you be open to a PR for this?

apocas commented 1 year ago

Yes definitely :)