2018-11-09 09:10:41 -05:00
|
|
|
---
|
|
|
|
title: "context create"
|
|
|
|
description: "The context create command description and usage"
|
|
|
|
keywords: "context, create"
|
|
|
|
---
|
|
|
|
|
|
|
|
# context create
|
|
|
|
|
|
|
|
```markdown
|
|
|
|
Usage: docker context create [OPTIONS] CONTEXT
|
|
|
|
|
|
|
|
Create a context
|
|
|
|
|
|
|
|
Docker endpoint config:
|
|
|
|
|
|
|
|
NAME DESCRIPTION
|
2019-03-22 10:20:40 -04:00
|
|
|
from Copy Docker endpoint configuration from an existing context
|
2018-11-09 09:10:41 -05:00
|
|
|
host Docker endpoint on which to connect
|
|
|
|
ca Trust certs signed only by this CA
|
|
|
|
cert Path to TLS certificate file
|
|
|
|
key Path to TLS key file
|
|
|
|
skip-tls-verify Skip TLS certificate validation
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2019-03-22 10:20:40 -04:00
|
|
|
$ docker context create my-context \
|
|
|
|
--description "some description" \
|
|
|
|
--docker "host=tcp://myserver:2376,ca=~/ca-file,cert=~/cert-file,key=~/key-file"
|
2018-11-09 09:10:41 -05:00
|
|
|
|
|
|
|
Options:
|
|
|
|
--description string Description of the context
|
|
|
|
--docker stringToString set the docker endpoint
|
|
|
|
(default [])
|
2019-03-22 10:20:40 -04:00
|
|
|
--from string Create the context from an existing context
|
2018-11-09 09:10:41 -05:00
|
|
|
```
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
2019-03-22 10:20:40 -04:00
|
|
|
Creates a new `context`. This allows you to quickly switch the cli
|
|
|
|
configuration to connect to different clusters or single nodes.
|
2018-11-09 09:10:41 -05:00
|
|
|
|
2020-05-07 07:53:25 -04:00
|
|
|
## Examples
|
|
|
|
|
2022-03-30 09:05:29 -04:00
|
|
|
### <a name=docker></a> Create a context with a docker endpoint (--docker)
|
2020-05-07 07:53:25 -04:00
|
|
|
|
2019-03-22 10:20:40 -04:00
|
|
|
To create a context from scratch provide the docker and, if required,
|
|
|
|
kubernetes options. The example below creates the context `my-context`
|
2022-02-23 12:05:12 -05:00
|
|
|
with a docker endpoint of `/var/run/docker.sock`:
|
2019-03-22 10:20:40 -04:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2020-05-07 07:53:25 -04:00
|
|
|
$ docker context create \
|
|
|
|
--docker host=unix:///var/run/docker.sock \
|
2020-09-29 15:59:36 -04:00
|
|
|
my-context
|
2019-03-22 10:20:40 -04:00
|
|
|
```
|
|
|
|
|
2022-03-30 09:05:29 -04:00
|
|
|
### <a name=from></a> Create a context based on an existing context (--from)
|
2020-05-07 07:53:25 -04:00
|
|
|
|
2019-03-22 10:20:40 -04:00
|
|
|
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`:
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2020-09-29 15:59:36 -04:00
|
|
|
$ docker context create --from existing-context my-context
|
2019-03-22 10:20:40 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
If the `--from` option is not set, the `context` is created from the current context:
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2019-03-22 10:20:40 -04:00
|
|
|
$ docker context create my-context
|
|
|
|
```
|
|
|
|
|
|
|
|
This can be used to create a context out of an existing `DOCKER_HOST` based script:
|
2018-11-09 09:10:41 -05:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2018-11-09 09:10:41 -05:00
|
|
|
$ source my-setup-script.sh
|
2019-03-22 10:20:40 -04:00
|
|
|
$ docker context create my-context
|
|
|
|
```
|
|
|
|
|
2022-02-23 12:05:12 -05:00
|
|
|
To source the `docker` endpoint configuration from an existing context
|
2019-03-22 10:20:40 -04:00
|
|
|
use the `--docker from=<context-name>` option. The example below creates a
|
|
|
|
new context named `my-context` using the docker endpoint configuration from
|
2022-02-23 12:05:12 -05:00
|
|
|
the existing context `existing-context`:
|
2019-03-22 10:20:40 -04:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2020-05-07 07:53:25 -04:00
|
|
|
$ docker context create \
|
|
|
|
--docker from=existing-context \
|
|
|
|
my-context
|
2018-11-09 09:10:41 -05:00
|
|
|
```
|
|
|
|
|
2022-02-23 12:05:12 -05:00
|
|
|
Docker endpoints configurations, as well as the description can be modified with
|
|
|
|
`docker context update`.
|
2020-05-07 07:53:25 -04:00
|
|
|
|
|
|
|
Refer to the [`docker context update` reference](context_update.md) for details.
|