docker context create

Description

Create a context

Usage

docker context create [OPTIONS] CONTEXT

Options

Name, shorthand Default Description
--default-stack-orchestrator Default orchestrator for stack operations to use with this context (swarm|kubernetes|all)
--description Description of the context
--docker set the docker endpoint
--from create context from a named context
--kubernetes set the kubernetes endpoint

Parent command

Command Description
docker context Manage contexts
Command Description
docker context create Create a context
docker context export Export a context to a tar or kubeconfig file
docker context import Import a context from a tar or zip file
docker context inspect Display detailed information on one or more contexts
docker context ls List contexts
docker context rm Remove one or more contexts
docker context update Update a context
docker context use Set the current docker context

Extended description

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 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:

$ 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:

$ docker context create my-context --from existing-context

If the --from option is not set, the context is created from the current context:

$ docker context create my-context

This can be used to create a context out of an existing DOCKER_HOST based script:

$ 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:

$ docker context create my-context \
      --docker from=existing-context \
      --kubernetes config-file=/home/me/my-kube-config

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:

$ 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

© 2019 Docker, Inc.
Licensed under the Apache License, Version 2.0.
Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.
Docker, Inc. and other parties may also have trademark rights in other terms used herein.
https://docs.docker.com/engine/reference/commandline/context_create/