Docker-Docs/_data/engine-cli/docker_context_create.yaml

126 lines
3.8 KiB
YAML
Raw Normal View History

2020-11-18 13:32:27 -05:00
command: docker context create
short: Create a context
long: |-
Creates a new `context`. This allows you to quickly switch the cli
configuration to connect to different clusters or single nodes.
usage: docker context create [OPTIONS] CONTEXT
pname: docker context
plink: docker_context.yaml
options:
- option: default-stack-orchestrator
value_type: string
description: |
Default orchestrator for stack operations to use with this context (swarm|kubernetes|all)
deprecated: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: description
value_type: string
description: Description of the context
deprecated: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: docker
value_type: stringToString
default_value: '[]'
description: set the docker endpoint
deprecated: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: from
value_type: string
description: create context from a named context
deprecated: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: kubernetes
value_type: stringToString
default_value: '[]'
description: set the kubernetes endpoint
deprecated: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
examples: |-
### Create a context with a docker and kubernetes endpoint
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 \
--docker host=unix:///var/run/docker.sock \
--kubernetes config-file=/home/me/my-kube-config \
my-context
```
### Create a context based on an existing context
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 --from existing-context my-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
```
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
$ docker context create \
--docker from=existing-context \
--kubernetes config-file=/home/me/my-kube-config \
my-context
```
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 \
--docker host=unix:///var/run/docker.sock \
--kubernetes from=existing-context \
my-context
```
Docker and Kubernetes endpoints configurations, as well as default stack
orchestrator and description can be modified with `docker context update`.
Refer to the [`docker context update` reference](context_update.md) for details.
deprecated: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false