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

Fast Context Switch: commands

Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
This commit is contained in:
Simon Ferquel
2018-11-09 15:10:41 +01:00
parent b34f340346
commit 591385a1d0
48 changed files with 2295 additions and 168 deletions

View File

@ -27,6 +27,7 @@ A self-sufficient runtime for containers.
Options:
--config string Location of client config files (default "/root/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")
-D, --debug Enable debug mode
--help Print usage
-H, --host value Daemon socket(s) to connect to (default [])
@ -78,6 +79,7 @@ by the `docker` command line:
`docker pull`) in `docker help` output, and only `Management commands` per object-type (e.g., `docker container`) are
printed. This may become the default in a future release, at which point this environment-variable is removed.
* `DOCKER_TMPDIR` Location for temporary Docker files.
* `DOCKER_CONTEXT` Specify the context to use (overrides DOCKER_HOST env var and default context set with "docker context use")
Because Docker is developed using Go, you can also use any environment
variables used by the Go runtime. In particular, you may find these useful:

View File

@ -0,0 +1,75 @@
---
title: "context create"
description: "The context create command description and usage"
keywords: "context, create"
---
<!-- This file is maintained within the docker/cli GitHub
repository at https://github.com/docker/cli/. Make all
pull requests against that repo. If you see this file in
another repository, consider it read-only there, as it will
periodically be overwritten by the definitive file. Pull
requests which include edits to this file in other repositories
will be rejected.
-->
# context create
```markdown
Usage: docker context create [OPTIONS] CONTEXT
Create a context
Docker endpoint config:
NAME DESCRIPTION
from-current Copy current Docker endpoint configuration
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
Kubernetes endpoint config:
NAME DESCRIPTION
from-current Copy current Kubernetes endpoint configuration
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"
Options:
--default-stack-orchestrator string Default orchestrator for
stack operations to use with
this context
(swarm|kubernetes|all)
--description string Description of the context
--docker stringToString set the docker endpoint
(default [])
--kubernetes stringToString set the kubernetes endpoint
(default [])
```
## Description
Creates a new `context`. This will allow 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:
```bash
$ source my-setup-script.sh
$ docker context create my-context --docker "from-current=true"
```
Similarly, to reference the currently active Kubernetes configuration, you can use `--kubernetes "from-current=true"`:
```bash
$ export KUBECONFIG=/path/to/my/kubeconfig
$ docker context create my-context --kubernetes "from-current=true" --docker "host=/var/run/docker.sock"
```
Docker and Kubernetes endpoints configurations, as well as default stack orchestrator and description can be modified with `docker context update`

View File

@ -0,0 +1,31 @@
---
title: "context export"
description: "The context export command description and usage"
keywords: "context, export"
---
<!-- This file is maintained within the docker/cli GitHub
repository at https://github.com/docker/cli/. Make all
pull requests against that repo. If you see this file in
another repository, consider it read-only there, as it will
periodically be overwritten by the definitive file. Pull
requests which include edits to this file in other repositories
will be rejected.
-->
# context export
```markdown
Usage: docker context export [OPTIONS] CONTEXT [FILE|-]
Export a context to a tar or kubeconfig file
Options:
--kubeconfig Export as a kubeconfig file
```
## Description
Exports a context in a file that can then be used with `docker context import` (or with `kubectl` if `--kubeconfig` is set).
Default output filename is `<CONTEXT>.dockercontext`, or `<CONTEXT>.kubeconfig` if `--kubeconfig` is set.
To export to `STDOUT`, you can run `docker context export my-context -`.

View File

@ -0,0 +1,22 @@
---
title: "context import"
description: "The context import command description and usage"
keywords: "context, import"
---
<!-- This file is maintained within the docker/cli GitHub
repository at https://github.com/docker/cli/. Make all
pull requests against that repo. If you see this file in
another repository, consider it read-only there, as it will
periodically be overwritten by the definitive file. Pull
requests which include edits to this file in other repositories
will be rejected.
-->
# context import
```markdown
Usage: docker context import [OPTIONS] CONTEXT FILE|-
Import a context from a tar file
```

View File

@ -0,0 +1,30 @@
---
title: "context ls"
description: "The context ls command description and usage"
keywords: "context, ls"
---
<!-- This file is maintained within the docker/cli GitHub
repository at https://github.com/docker/cli/. Make all
pull requests against that repo. If you see this file in
another repository, consider it read-only there, as it will
periodically be overwritten by the definitive file. Pull
requests which include edits to this file in other repositories
will be rejected.
-->
# context ls
```markdown
Usage: docker context ls [OPTIONS]
List contexts
Aliases:
ls, list
Options:
--format string Pretty-print contexts using a Go template
(default "table")
-q, --quiet Only show context names
```

View File

@ -0,0 +1,28 @@
---
title: "context rm"
description: "The context rm command description and usage"
keywords: "context, rm"
---
<!-- This file is maintained within the docker/cli GitHub
repository at https://github.com/docker/cli/. Make all
pull requests against that repo. If you see this file in
another repository, consider it read-only there, as it will
periodically be overwritten by the definitive file. Pull
requests which include edits to this file in other repositories
will be rejected.
-->
# context rm
```markdown
Usage: docker context rm CONTEXT [CONTEXT...]
Remove one or more contexts
Aliases:
rm, remove
Options:
-f, --force Force the removal of a context in use
```

View File

@ -0,0 +1,60 @@
---
title: "context update"
description: "The context update command description and usage"
keywords: "context, update"
---
<!-- This file is maintained within the docker/cli GitHub
repository at https://github.com/docker/cli/. Make all
pull requests against that repo. If you see this file in
another repository, consider it read-only there, as it will
periodically be overwritten by the definitive file. Pull
requests which include edits to this file in other repositories
will be rejected.
-->
# context update
```markdown
Usage: docker context update [OPTIONS] CONTEXT
Update a context
Docker endpoint config:
NAME DESCRIPTION
from-current Copy current Docker endpoint configuration
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
Kubernetes endpoint config:
NAME DESCRIPTION
from-current Copy current Kubernetes endpoint configuration
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 update 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
stack operations to use with
this context
(swarm|kubernetes|all)
--description string Description of the context
--docker stringToString set the docker endpoint
(default [])
--kubernetes stringToString set the kubernetes endpoint
(default [])
```
## Description
Updates an existing `context`.
See [context create](context_create.md)

View File

@ -0,0 +1,25 @@
---
title: "context use"
description: "The context use command description and usage"
keywords: "context, use"
---
<!-- This file is maintained within the docker/cli GitHub
repository at https://github.com/docker/cli/. Make all
pull requests against that repo. If you see this file in
another repository, consider it read-only there, as it will
periodically be overwritten by the definitive file. Pull
requests which include edits to this file in other repositories
will be rejected.
-->
# context use
```markdown
Usage: docker context use CONTEXT
Set the current docker context
```
## Description
Set the default context to use, when `DOCKER_HOST`, `DOCKER_CONTEXT` environment variables and `--host`, `--context` global options are not set.

View File

@ -182,3 +182,15 @@ read the [`dockerd`](dockerd.md) reference page.
| [plugin push](plugin_push.md) | Push a plugin to a registry |
| [plugin rm](plugin_rm.md) | Remove a plugin |
| [plugin set](plugin_set.md) | Change settings for a plugin |
### Context commands
| Command | Description |
|:--------|:-------------------------------------------------------------------|
| [context create](context_create.md) | Create a context |
| [context export](context_export.md) | Export a context |
| [context import](context_import.md) | Import a context |
| [context ls](context_ls.md) | List contexts |
| [context rm](context_rm.md) | Remove one or more contexts |
| [context update](context_update.md) | Update a context |
| [context use](context_use.md) | Set the current docker context |