1
0
mirror of https://github.com/docker/cli.git synced 2025-08-01 04:26:55 +03:00

add --from option to context create

--from creates a context from a named context.
By default `context create` will create a context from the current context.
Replaced "from-current=" docker/kubernetes option with "from=" to allow specifying which context to copy the settings from.

Signed-off-by: Nick Adcock <nick.adcock@docker.com>
This commit is contained in:
Nick Adcock
2019-03-22 14:20:40 +00:00
parent f40f9c240a
commit 8bb152d967
6 changed files with 301 additions and 56 deletions

View File

@ -23,7 +23,7 @@ Create a context
Docker endpoint config:
NAME DESCRIPTION
from-current Copy current Docker endpoint configuration
from Copy Docker endpoint configuration from an existing context
host Docker endpoint on which to connect
ca Trust certs signed only by this CA
cert Path to TLS certificate file
@ -33,14 +33,16 @@ skip-tls-verify Skip TLS certificate validation
Kubernetes endpoint config:
NAME DESCRIPTION
from-current Copy current Kubernetes endpoint configuration
from Copy Kubernetes endpoint configuration from an existing context
config-file Path to a Kubernetes config file
context-override Overrides the context set in the kubernetes config file
namespace-override Overrides the namespace set in the kubernetes config file
Example:
$ docker context create my-context --description "some description" --docker "host=tcp://myserver:2376,ca=~/ca-file,cert=~/cert-file,key=~/key-file"
$ docker context create my-context \
--description "some description" \
--docker "host=tcp://myserver:2376,ca=~/ca-file,cert=~/cert-file,key=~/key-file"
Options:
--default-stack-orchestrator string Default orchestrator for
@ -52,24 +54,68 @@ Options:
(default [])
--kubernetes stringToString set the kubernetes endpoint
(default [])
--from string Create the context from an existing context
```
## Description
Creates a new `context`. This will allow you to quickly switch the cli configuration to connect to different clusters or single nodes.
Creates a new `context`. This allows you to quickly switch the cli
configuration to connect to different clusters or single nodes.
To create a `context` out of an existing `DOCKER_HOST` based script, you can use the `from-current` config key:
To create a context from scratch provide the docker and, if required,
kubernetes options. The example below creates the context `my-context`
with a docker endpoint of `/var/run/docker.sock` and a kubernetes configuration
sourced from the file `/home/me/my-kube-config`:
```bash
$ docker context create my-context \
--docker host=/var/run/docker.sock \
--kubernetes config-file=/home/me/my-kube-config
```
Use the `--from=<context-name>` option to create a new context from
an existing context. The example below creates a new context named `my-context`
from the existing context `existing-context`:
```bash
$ docker context create my-context --from existing-context
```
If the `--from` option is not set, the `context` is created from the current context:
```bash
$ docker context create my-context
```
This can be used to create a context out of an existing `DOCKER_HOST` based script:
```bash
$ source my-setup-script.sh
$ docker context create my-context --docker "from-current=true"
$ docker context create my-context
```
Similarly, to reference the currently active Kubernetes configuration, you can use `--kubernetes "from-current=true"`:
To source only the `docker` endpoint configuration from an existing context
use the `--docker from=<context-name>` option. The example below creates a
new context named `my-context` using the docker endpoint configuration from
the existing context `existing-context` and a kubernetes configuration sourced
from the file `/home/me/my-kube-config`:
```bash
$ export KUBECONFIG=/path/to/my/kubeconfig
$ docker context create my-context --kubernetes "from-current=true" --docker "host=/var/run/docker.sock"
$ docker context create my-context \
--docker from=existing-context \
--kubernetes config-file=/home/me/my-kube-config
```
Docker and Kubernetes endpoints configurations, as well as default stack orchestrator and description can be modified with `docker context update`
To source only the `kubernetes` configuration from an existing context use the
`--kubernetes from=<context-name>` option. The example below creates a new
context named `my-context` using the kuberentes configuration from the existing
context `existing-context` and a docker endpoint of `/var/run/docker.sock`:
```bash
$ docker context create my-context \
--docker host=/var/run/docker.sock \
--kubernetes from=existing-context
```
Docker and Kubernetes endpoints configurations, as well as default stack
orchestrator and description can be modified with `docker context update`

View File

@ -23,7 +23,7 @@ Update a context
Docker endpoint config:
NAME DESCRIPTION
from-current Copy current Docker endpoint configuration
from Copy Docker endpoint configuration from an existing context
host Docker endpoint on which to connect
ca Trust certs signed only by this CA
cert Path to TLS certificate file
@ -33,7 +33,7 @@ skip-tls-verify Skip TLS certificate validation
Kubernetes endpoint config:
NAME DESCRIPTION
from-current Copy current Kubernetes endpoint configuration
from Copy Kubernetes endpoint configuration from an existing context
config-file Path to a Kubernetes config file
context-override Overrides the context set in the kubernetes config file
namespace-override Overrides the namespace set in the kubernetes config file