Skip to content

Difficult to execute commands when currentContext is invalid #1955

@kinghuang

Description

@kinghuang

Description

If the current context is not valid, it is not easy to run any CLI commands, including switching to a valid context.

Steps to reproduce the issue:

Assume there are contexts named default and context-two.

  1. Make context-two the current context.
  2. Set DOCKER_CONTEXT=default to override it in the current shell.
  3. Remove context-two.
  4. Attempt to do something with the Docker CLI, like docker version.
$ docker context ls --format 'table {{ .Name }}\t{{ .Current }}'
NAME                <no value>
context-two         true
default             false
$ export DOCKER_CONTEXT=default
$ docker context rm context-two
context-two

Describe the results you received:

Any CLI operation results in an error. It is not possible to switch to a valid context using docker context use ….

$ docker version
Current context "context-two" is not found on the file system, please check your config file at /Users/king.huang/.docker/config.json
$ docker context use default
Current context "context-two" is not found on the file system, please check your config file at /Users/king.huang/.docker/config.json

Describe the results you expected:

It should be possible to at least list and switch to a valid context.

Additional information you deem important (e.g. issue happens only occasionally):

When removing the current context specified in config.json, perhaps the CLI should change the value of currentContext to something like default.

The current context can be fixed by editing config.json manually, or using the DOCKER_CONTEXT environment variable to switch to a valid context, and then using a valid context.

$ export DOCKER_CONTEXT=default
$ docker context use default
default
Current context is now "default"

Output of docker version:

Client: Docker Engine - Community
 Version:           19.03.0-rc2
 API version:       1.40
 Go version:        go1.12.5
 Git commit:        f97efcc
 Built:             Wed Jun  5 01:37:53 2019
 OS/Arch:           darwin/amd64
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          19.03.0-rc2
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.5
  Git commit:       f97efcc
  Built:            Wed Jun  5 01:42:10 2019
  OS/Arch:          linux/amd64
  Experimental:     true
 containerd:
  Version:          v1.2.6
  GitCommit:        894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc:
  Version:          1.0.0-rc8
  GitCommit:        425e105d5a03fabd737a126ad93d62a9eeede87f
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Output of docker info:

Client:
 Debug Mode: false
 Plugins:
  app: Docker Application (Docker Inc., v0.8.0-rc1)
  buildx: Build with BuildKit (Docker Inc., v0.2.2-tp-docker)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 300
 Server Version: 19.03.0-rc2
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: active
  NodeID: ilntgb4sbycucyl3iiva1wk3p
  Is Manager: true
  ClusterID: wsz99afbhy169obu69h1eq7z0
  Managers: 1
  Nodes: 1
  Default Address Pool: 10.0.0.0/8  
  SubnetSize: 24
  Data Path Port: 4789
  Orchestration:
   Task History Retention Limit: 5
  Raft:
   Snapshot Interval: 10000
   Number of Old Snapshots to Retain: 0
   Heartbeat Tick: 1
   Election Tick: 10
  Dispatcher:
   Heartbeat Period: 5 seconds
  CA Configuration:
   Expiry Duration: 3 months
   Force Rotate: 0
  Autolock Managers: false
  Root Rotation In Progress: false
  Node Address: 192.168.65.3
  Manager Addresses:
   192.168.65.3:2377
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.9.125-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 6
 Total Memory: 11.71GiB
 Name: docker-desktop
 ID: b5307ed3-4dc8-4eb4-b931-138544ef581f
 Docker Root Dir: /var/lib/docker
 Debug Mode: true
  File Descriptors: 45
  Goroutines: 157
  System Time: 2019-06-18T14:25:25.8970508Z
  EventsListeners: 2
 HTTP Proxy: gateway.docker.internal:3128
 HTTPS Proxy: gateway.docker.internal:3129
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: true
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

Additional environment details (AWS, VirtualBox, physical, etc.):

Docker for Mac 2.0.5.0.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions