Check the Active Docker Context with docker context show

One forgotten docker context use from last week, and your next docker compose down lands on the wrong machine. docker context show prints the active context name so you can catch that first.

You will confirm which context your shell has selected before you run a container, build an image or inspect a remote daemon. The command is read-only and prints one name. Allow about five minutes.

You need the Docker CLI. This guide uses Docker CE CLI 29.8.1, package version 5:29.8.1-1~ubuntu.24.04~noble on the reference machine.

1. Print the current context

Run the command before any Docker operation whose destination matters:

$ docker context show
default

The output is the name of the active context, followed by a newline. On the reference machine it is default. Yours may differ, and that difference can change which Docker daemon receives later commands.

Checkpoint: if you expected a named context but saw default, stop and investigate. Do not start a container until the name matches your intention.

2. Compare the name with the context list

Use docker context ls when you need the endpoint and the visible selection marker as well as the name:

$ docker context ls
NAME        DESCRIPTION                               DOCKER ENDPOINT               ERROR
default *   Current DOCKER_HOST based configuration   unix:///var/run/docker.sock

The asterisk marks the context selected for ordinary Docker commands. The description, endpoint and error column depend on your client configuration. The cross-check that matters: the row with * has the same name that docker context show printed.

This list describes client-side selection. It does not prove that a remote endpoint is reachable or that your account is authorised to use it. A context can be selected while its daemon is stopped or inaccessible.

3. Understand what selects the result

docker context show has no command-specific flags. Docker's global selection mechanisms can still affect its result: the DOCKER_CONTEXT environment variable and the global --context option. The option goes before the context show subcommand:

$ DOCKER_CONTEXT=default docker context show
default
$ docker --context default context show
default

These examples force the named context for that invocation and leave the saved current context unchanged. Use a real context name in place of default. If the name does not exist, Docker reports an error instead of printing a valid context, so check it with docker context ls first.

Environment variables are an easy distraction during troubleshooting. Check whether the shell has one set:

$ if [ -n "${DOCKER_CONTEXT:-}" ]; then
    printf 'DOCKER_CONTEXT=%s\n' "$DOCKER_CONTEXT"
  else
    printf '%s\n' 'DOCKER_CONTEXT is not set'
  fi
DOCKER_CONTEXT is not set

Tip: A value in a shell startup file, CI job or wrapper script can make a command target a different daemon from the one you see in another terminal. The global --context option takes precedence for the individual Docker invocation.

4. Check the target before a consequential operation

Context selection itself does not start or stop anything, but the next command might. Put an explicit check in a script when using the wrong daemon would be costly:

expected_context='staging'
actual_context=$(docker context show) || exit 1
if [ "$actual_context" != "$expected_context" ]; then
    printf 'Refusing to continue: expected %s, got %s\n' \
        "$expected_context" "$actual_context" >&2
    exit 1
fi
printf 'Docker context confirmed: %s\n' "$actual_context"

Replace staging with an intentional context name, not a placeholder you might forget. This check does not authenticate to the daemon or test a service. Add a separate, harmless connectivity check if the workflow needs one, and review it for the permissions and side effects of your environment.

Tip: Do not use sudo merely to display the context. The command reads Docker client configuration and normally runs as your ordinary user. Through sudo it may read root's Docker configuration and show a different answer, which makes the check less useful.

5. Change selection only when you mean to

docker context show does not change anything. The separate docker context use NAME command changes the saved current context for later commands, so treat it as a configuration change. Confirm the target name first, then verify after changing it:

$ docker context use staging
staging
Current context is now "staging"
$ docker context show
staging

Recovery: if that selection was accidental, switch back using the exact previous name.

$ docker context use default
default
Current context is now "default"

Changing context does not move containers or images between daemons. It only changes where later Docker CLI requests are sent.

Warning: Before removing a context or deleting a remote resource, check the selected name and endpoint again. Those actions are outside this read-only check and may be irreversible.

Done means