pack
pack copied to clipboard
Detect docker endpoint from docker context
When using Docker rootless, the endpoint that should be used is not the default /var/run/docker.sock
location. Instead docker CLI can be pointed to a different (context)[https://docs.docker.com/engine/security/rootless/#client]), which defaults to another location like unix:///run/user/1000/docker.sock
.
The Docker CLI uses context for defaults, so there is no need to set DOCKER_HOST variable if you run docker context use rootless
first. Can pack
lookup the default endpoint from docker context if DOCKER_HOST is not set? This would make it consistent with the docker CLI.
+1 for this. Hitting a similar issue, not using rootless, but another tool that sets the docker context
and expects that to be used as opposed to DOCKER_HOST
. Having to set DOCKER_HOST
overrides the docker context
setting and is just an extra step to make things work.
It would be nice if pack
were able to detect the selected context.
For what it's worth:
It looks like ~/.docker/config.json
has a currentContext
property which contains the name of the context. There is also a ~/.docker/contexts
folder that contains the actual information. I'm not certain about the folder structure exactly. It looks like this on my machine: .docker/contexts/meta/<hash?>/meta.json
where meta.json
contains the details for the selected context.
Ex:
{"Name":"best-host-ever","Metadata":{},"Endpoints":{"docker":{"Host":"unix:///home/user/.config/docker.sock","SkipTLSVerify":false}}}
Thanks @dmikusa-pivotal , you provided answers to questions that immediately come to my mind. It seems like this is a docker CLI specific implementation. I'd be okay with integrating with it.
@matejvasek does postman have something similar?
I too am running into this problem (with Docker Desktop for Mac), where pack build ...
fails to connect b/c I have no /var/run/docker.sock
- but the docker
CLI itself works just fine. Thhe docker context explains why it is the case:
$ docker context list
NAME TYPE DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
default moby Current DOCKER_HOST based configuration unix:///var/run/docker.sock https://kubernetes.docker.internal:6443 (default) swarm
desktop-linux * moby unix:///Users/me/.docker/run/docker.sock
$ docker context show
desktop-linux
so the default
context uses the standard socket but is not active and the socket does not exist. Instead, the active context is desktop-linux
, which uses a socket in the user's home dir (which does exist).
(I have also created a StackOverflow Q&A for this, as it took me quite a while to find the problem and solution.)
Duplicated of #1830
Closing this one in favor of #1830