docker / docker/cli

Feature Request: Switch between multiple related hosts in a context

Open
#1,931 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/context kind/feature
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

Description

The new context feature in CLI 19.03 makes it easy to switch between multiple Docker hosts and Kubernetes endpoints. I often deal with groups of Docker hosts in a cluster that share a common set of TLS cert and key. There isn't a convenient way to use a context, which has the cert and key, but switch between multiple hosts.

Steps to reproduce the issue:

  1. Assume there is a context named node-1 that has a Docker endpoint at tcp://node-1:2376, ca, cert, and key defined.
  2. Based on the node-1 context, attempt to connect to an endpoint at tcp://node-2:2376 using the same certs.

Describe the results you received:

Using the node-1 context, I attempted to directly create a node-2 context with a different endpoint. This didn't work because --docker cannot be used when creating a context from another.

$ docker context create --from node-1 --docker host=tcp://node-2:2376 node-2
cannot use --docker or --kubernetes flags when --from is set

I then created a node-2 context from node-1, and attempted to update just the endpoint address. This didn't work, because it seems the existing ca, cert, and key parameter values aren't kept.

$ docker context create --from psc-dev-gen node-2
$ docker context update --docker tcp://node-2:2376 node-2
$ docker context use node-2
$ docker info
Server:
ERROR: Get http://node-2:2376/v1.40/info: net/http: HTTP/1.x transport connection broken: malformed HTTP response "\x15\x03\x01\x00\x02\x02".
* Are you trying to connect to a TLS-enabled daemon without TLS?
errors pretty printing info

I also tried using the original context, but setting DOCKER_HOST. However, setting the DOCKER_HOST environment variable forces the context back to default.

$ docker context use node-1
node-1
Current context is now "node-1"
$ docker context ls --format 'table {{.Name}}\t{{.DockerEndpoint}}'
NAME                DOCKER ENDPOINT
default *           tcp://node-2:2376
node-1              tcp://node-1:2376
node-2              tcp://node-2:2376
Warning: DOCKER_HOST environment variable overrides the active context. To use a context, either set the global --context flag, or unset DOCKER_HOST environment variable.

Describe the results you expected:

Some way to use a context that has ca, cert, and key set, and be able to easily hop between a set of related Docker hosts. Using the pre-context method via environment variables, it was easy to set DOCKER_CONFIG to the directory with certs and DOCKER_TLS_VERIFY=1, then just change DOCKER_HOST to hop between hosts.

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

N/A

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:12 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.0-beta3
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.4
  Git commit:       c55e026
  Built:            Thu Apr 25 19:13:00 2019
  OS/Arch:          linux/amd64
  Experimental:     true
 containerd:
  Version:          v1.2.6
  GitCommit:        894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc:
  Version:          1.0.0-rc7+dev
  GitCommit:        029124da7af7360afa781a0234d1b083550f797c
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Output of docker info:

N/A

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the CLI entry points for docker context create, docker context update, and context selection, then reproduce the shown commands with shared TLS settings. Done means a context can retain its ca, cert, and key while switching between related Docker host endpoints without falling back to the default context.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.