fussybeaver / bollard

Docker daemon API in Rust
Apache License 2.0
911 stars 134 forks source link

Handle when socket is in the home directory #345

Open banool opened 1 year ago

banool commented 1 year ago

Hey hey,

Currently when creating a Docker client like this:

Docker::connect_with_local_defaults

It looks for the socket at /var/run/docker.sock. The new default in Docker Desktop is to put the socket in your home dir instead, so new Docker users won't have the socket there, but at ~/.docker/run/docker.sock.

Would you accept a PR that makes the function look first for the socket at /var/run/docker.sock and then at ~/.docker/run/docker.sock?

Thanks!

banool commented 1 year ago

This is how I'm handling this for now myself btw: https://github.com/aptos-labs/aptos-core/pull/10654.

fussybeaver commented 1 year ago

I was looking to see if the official moby source does this, as I guess that's slightly different to Docker Desktop ? (which OS are you referring to?)

I didn't find anything in the moby source that there's a fallback, but I did see this line: https://github.com/moby/moby/blob/d83ead84340ca8a586186a13d4d7169931593b5e/contrib/dockerd-rootless-setuptool.sh#L345

which suggests that one should set the DOCKER_HOST environment variable, which should also work in Bollard...

banool commented 1 year ago

In my case I'm mostly referring to MacOS, but I suppose it might be relevant to Linux too. Just not Windows, since it's always just that same named pipe.

As for the DOCKER_HOST environment variable, it seems like Docker when installed doesn't configure this. The user could set this themselves but that's no better than just using the env var to tell Bollard where to find the Docker socket. What I'm sort of hoping for / planning here is to have Bollard try /var/run/docker.sock first and then if that's not there, try the one in the home dir. In other words ideally the default connect function on Bollard should just work out of the box with either socket location.

fussybeaver commented 1 year ago

Thanks, I noticed when looking more closely at this that there's a docker command docker context which we don't surface in Bollard... I'll need to take another look when I have some time.

In principal it sounds fine to have that fallback added, if you're interested in that.

banool commented 1 year ago

Neato sounds good! I'll put this on my to do list.