1
0
mirror of https://github.com/docker/cli.git synced 2025-04-20 06:27:49 +03:00
cli/docs/reference/commandline/context_show.md
Kevin Alvarez 79c9e527a3
docs: generate markdown
Keep frontmatter for docker, dockerd and index markdown files.
Also needs to move cli.md > docker.md before generation and
then move it back because cli.md is needed for yaml generation on docs
website: https://github.com/docker/cli/pull/3924#discussion_r1059986605

Signed-off-by: Kevin Alvarez <crazy-max@users.noreply.github.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-01-06 22:36:47 +01:00

1.3 KiB

context show

Print the name of the current context

Description

Print the name of the current context, possibly set by DOCKER_CONTEXT environment variable or --context global option.

Examples

Print the current context

The following example prints the currently used docker context:

$ docker context show'
default

As an example, this output can be used to dynamically change your shell prompt to indicate your active context. The example below illustrates how this output could be used when using Bash as your shell.

Declare a function to obtain the current context in your ~/.bashrc, and set this command as your PROMPT_COMMAND

function docker_context_prompt() {
        PS1="context: $(docker context show)> "
}

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>