-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(docker): Honor the host specified in current docker context #464
feat(docker): Honor the host specified in current docker context #464
Conversation
return defaultDockerHost, nil | ||
} | ||
|
||
storeConfig := ctxstore.NewConfig( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain what's happening from here to line 380?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Here's the gist of what's happening.
Line: 364: We create a new Store
by passing the path to store directory ($HOME/.docker/contexts
) and the "store config" (which is used to return a typed value from a "generic" value that the Store
can store).
Here, we are interested in retrieving the information associated with a docker context
aka the EndpointMeta
, which contains the docker host information. That is why the "store config" includes a getter
meant for the EndpointMeta
(Line: 359).
The rest of the surrounding lines are just plumbing code to extract the host information and error handling.
Bonus:
What's inside the contexts
directory?
$ tree ~/.docker/contexts/meta/
$HOME/.docker/contexts/meta/
├── 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
│ └── meta.json
├── ed027fa4e9dc0950c3d3acf4a7bbaf242810ff73290de387e34e6d26c2a5b21b
│ └── meta.json
├── f24fd3749c1368328e2b149bec149cb6795619f244c5b584e844961215dadd16
│ └── meta.json
└── fe9c6bd7a66301f49ca9b6a70b217107cd1284598bfc254700c989b916da791e
└── meta.json
Those directory names are the sha256
sum of the of the context name. For example, one of my context is named colima
.
$ echo -n "colima"| openssl sha256
(stdin)= f24fd3749c1368328e2b149bec149cb6795619f244c5b584e844961215dadd16
What's inside the meta.json
?
$ cat $HOME/.docker/contexts/meta/f24fd3749c1368328e2b149bec149cb6795619f244c5b584e844961215dadd16/meta.json | jq '.'
{
"Name": "colima",
"Metadata": {
"Description": "colima"
},
"Endpoints": {
"docker": {
"Host": "unix:///$HOME/.colima/default/docker.sock",
"SkipTLSVerify": false
}
}
}
One can have multiple docker hosts that they manage and can switch between them using the "docker context" command. Previously, we used to connect to either the "default docker host" (for example, unix:///var/run/docker.sock in case of Linux/macOS) or to the host specified via the "DOCKER_HOST" environment variable. However, if one switched to a different context, we had no way of detecting that. Now, we determine the docker host that we connect to by evaluating the following sources in decreasing order of precedence: - value of "DOCKER_HOST" environment variable - host specified in the context set via the "DOCKER_CONTEXT" environment variable - "default docker host" as applicable, otherwise Fixes: jesseduffield#285 Signed-off-by: Rajiv Kushwaha <raj25by10@gmail.com>
9d91a04
to
899b42d
Compare
Is not resolved if you create link to colima with default docker.sock? |
Sorry this took me so long to get back to @rajiv-k . Great work! |
Thank you for adding this feature! I added the feature request in December 2021. Really happy to see it get added. |
@rajiv-k - I was testing out this new functionality. Is honoring the docker context only available for
|
One can have multiple docker hosts that they manage and can switch between them using the "docker context" command.
Previously, we used to connect to either the "default docker host" (for example,
unix:///var/run/docker.sock
in case of Linux/macOS) or to the host specified via the"DOCKER_HOST"
environment variable. However, if one switched to a different context, we had no way of detecting that.Now, we determine the docker host that we connect to by evaluating the following sources in decreasing order of precedence:
"DOCKER_HOST"
environment variable"DOCKER_CONTEXT"
environment variableFixes: #285