docker context show


Print the name of the current context

Usage

$ docker context show

Description

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

For example uses of this command, refer to the examples section below.

Examples

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>

Parent command

Command Description
docker context Manage contexts
Command Description
docker context create Create a context
docker context export Export a context to a tar archive FILE or a tar stream on STDOUT.
docker context import Import a context from a tar or zip file
docker context inspect Display detailed information on one or more contexts
docker context ls List contexts
docker context rm Remove one or more contexts
docker context show Print the name of the current context
docker context update Update a context
docker context use Set the current docker context