Skip to content
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

Add "context" to "docker version" and "docker info" #2500

Merged
merged 2 commits into from
May 7, 2020

Conversation

thaJeztah
Copy link
Member

This adds the currently selected "docker context" to the output of docker version (and docker info), which allows users to see which context is selected to produce the version output, and can be used (for example), to set the prompt to the currently selected context:

(in ~/.bashrc):

function docker_context_prompt() {
        PS1="context: $(docker version --format='{{.Client.Context}}')> "
}

PROMPT_COMMAND=docker_context_prompt

After reloading the ~/.bashrc, the prompt now shows the currently selected
docker context:

$ source ~/.bashrc
context: default> docker context create --docker host=unix:///var/run/docker.sock my-context
my-context
Successfully created context "my-context"
context: default> docker context use my-context
my-context
Current context is now "my-context"
context: my-context> docker context use default
default
Current context is now "default"
context: default>

@thaJeztah
Copy link
Member Author

This adds the currently selected "docker context" to the output
of "docker version", which allows users to see which context
is selected to produce the version output, and can be used (for
example), to set the prompt to the currently selected context:

(in `~/.bashrc`):

```bash
function docker_context_prompt() {
        PS1="context: $(docker version --format='{{.Client.Context}}')> "
}

PROMPT_COMMAND=docker_context_prompt
```

After reloading the `~/.bashrc`, the prompt now shows the currently selected
`docker context`:

```bash
$ source ~/.bashrc
context: default> docker context create --docker host=unix:///var/run/docker.sock my-context
my-context
Successfully created context "my-context"
context: default> docker context use my-context
my-context
Current context is now "my-context"
context: my-context> docker context use default
default
Current context is now "default"
context: default>
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Copy link
Contributor

@simonferquel simonferquel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -32,6 +32,7 @@ Client:{{if ne .Platform.Name ""}} {{.Platform.Name}}{{end}}
Git commit: {{.GitCommit}}
Built: {{.BuildTime}}
OS/Arch: {{.Os}}/{{.Arch}}
Context: {{.Context}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we really need this context in version 🤔
I think that version should mostly print static informations, but context is by nature purely dynamic.
That said, it may help the user to understand which daemon she's talking to, so which daemon version are printed.
I'm a bit over the fence 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main reason for putting it here, is that docker info requires a daemon connection (and is rather heavy-weight), so if someone wants to use it to set their prompt (as the example), they likely wouldn't want it to be taken from docker info.

We could add, e.g., the option to call docker context use (without argument) to print the current context, or add a docker context show-current subcommand (but not sure if the last one is "great" to have a subcommand just for that); WDYT?

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AkihiroSuda
Copy link
Collaborator

Can we also print non-context DOCKER_HOST?

@thaJeztah
Copy link
Member Author

@AkihiroSuda Actually wanted to do that as well; didn't make the PR yet, but want to do that soon

@silvin-lubecki silvin-lubecki merged commit 7cd6e89 into docker:master May 7, 2020
@thaJeztah thaJeztah deleted the version_context branch May 8, 2020 00:23
@colegatron
Copy link

Any idea when 20.10 is going to be released? I am interested in (any) solution to solve the 'docker context ls' slowness to get the current context. My prompt displays kubernetes, git, and other info blazing fast, but docker context is damn slow for remotes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants