JavAlex
JavAlex

Reputation: 5944

Docker context not changing (docker context use)

I am using the command docker context use in order to set the active Docker context:

> docker context use aws-context
aws-context

However, the active Docker context does not change for some reason.

When I subsequently type docker context show, the activated context is still the default context:

> docker context show
default

When I list the existing contexts, the asterisk is still behind the default context:

> docker context ls
NAME                TYPE                DESCRIPTION                              DOCKER ENDPOINT             
aws-context         ecs                 (eu-west-1)                                                                  
default *           moby                Current DOCKER_HOST based configuration  tcp://192.168.99.100:2376          

How can I change the Docker context?

Upvotes: 9

Views: 13318

Answers (3)

Rahulkg007
Rahulkg007

Reputation: 77

Setting the docker context to default worked for me.

docker context use default

Upvotes: 0

pb.
pb.

Reputation: 341

I also experienced problems with env variable: DOCKER_CONTEXT.
Make sure that you are setting it correctly...

instead of:

pb@L1:~$ DOCKER_CONTEXT=example
pb@L1:~$ echo $DOCKER_CONTEXT
example

use:

pb@L1:~$ export DOCKER_CONTEXT=example
pb@L1:~$ echo $DOCKER_CONTEXT 
example

alternatively (if you are using docker extension in VSCode, modify settings.json)
ctrl+shift+p -> Open workspace settings (JSON)

{
    "docker.context":"remote_workstation"
}

Upvotes: 0

programmerq
programmerq

Reputation: 6534

If you have the DOCKER_HOST environment variable set, it will always take precedence over the newer docker context use workflow.

Type env | grep DOCKER in your shell to see if you have any docker-specific variables set. unset them by typing unset DOCKER_HOST. Other variables such as DOCKER_CONTEXT may also get in the way.

The docker context use command should work fine once that variable is out of the way.

This is noted in the docs here:

The easiest way to see what a context looks like is to view the default context.

$ docker context ls
NAME          DESCRIPTION     DOCKER ENDPOINT              KUBERNETES ENDPOINT      ORCHESTRATOR
default *     Current...      unix:///var/run/docker.sock                           swarm

This shows a single context called “default”. It’s configured to talk to a Swarm cluster through the local /var/run/docker.sock Unix socket. It has no Kubernetes endpoint configured.

The asterisk in the NAME column indicates that this is the active context. This means all docker commands will be executed against the “default” context unless overridden with environment variables such as DOCKER_HOST and DOCKER_CONTEXT, or on the command-line with the --context and --host flags.

(bold added by me)

Upvotes: 20

Related Questions