summaryrefslogtreecommitdiff
path: root/devdocs/docker/engine%2Freference%2Fcommandline%2Fcontext_create%2Findex.html
blob: 8fa4d0bca07b46430098d89ba0eeab1bd8ca2279 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<h1>docker context create</h1>  <p><br></p> <p>Create a context</p> <h2 id="usage">Usage</h2> <div class="highlight"><pre class="highlight" data-language="">$ docker context create [OPTIONS] CONTEXT
</pre></div> <p>Refer to the <a href="#options">options section</a> for an overview of available <a href="#options"><code class="language-plaintext highlighter-rouge">OPTIONS</code></a> for this command.</p> <h2 id="description">Description</h2> <p name="extended-description">Creates a new <code class="language-plaintext highlighter-rouge">context</code>. This allows you to quickly switch the cli configuration to connect to different clusters or single nodes.</p> <p>For example uses of this command, refer to the <a href="#examples">examples section</a> below.</p> <h2 id="options">Options</h2> <table> <thead> <tr> <td>Name, shorthand</td> <td>Default</td> <td>Description</td> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">--default-stack-orchestrator</code></td> <td></td> <td>
<a href="../../../deprecated/index" target="_blank" rel="noopener" class="_"><span class="badge badge-danger" data-toggle="tooltip" title="Read the deprecation reference (in a new window).">deprecated</span></a><br>Default orchestrator for stack operations to use with this context (swarm|kubernetes|all)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--description</code></td> <td></td> <td>Description of the context</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--docker</code></td> <td></td> <td>set the docker endpoint</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--from</code></td> <td></td> <td>create context from a named context</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--kubernetes</code></td> <td></td> <td>
<a href="../../../deprecated/index" target="_blank" rel="noopener" class="_"><span class="badge badge-danger" data-toggle="tooltip" title="Read the deprecation reference (in a new window).">deprecated</span></a><span class="badge badge-info" data-toggle="tooltip" title="This option works for the Kubernetes orchestrator.">Kubernetes</span><br>set the kubernetes endpoint</td> </tr>  </tbody> </table>  <h2 id="examples">Examples</h2> <h3 id="create-a-context-with-a-docker-and-kubernetes-endpoint">Create a context with a docker and kubernetes endpoint</h3> <p>To create a context from scratch provide the docker and, if required, kubernetes options. The example below creates the context <code class="language-plaintext highlighter-rouge">my-context</code> with a docker endpoint of <code class="language-plaintext highlighter-rouge">/var/run/docker.sock</code> and a kubernetes configuration sourced from the file <code class="language-plaintext highlighter-rouge">/home/me/my-kube-config</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker context create \
    --docker host=unix:///var/run/docker.sock \
    --kubernetes config-file=/home/me/my-kube-config \
    my-context
</pre></div> <h3 id="create-a-context-based-on-an-existing-context">Create a context based on an existing context</h3> <p>Use the <code class="language-plaintext highlighter-rouge">--from=&lt;context-name&gt;</code> option to create a new context from an existing context. The example below creates a new context named <code class="language-plaintext highlighter-rouge">my-context</code> from the existing context <code class="language-plaintext highlighter-rouge">existing-context</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker context create --from existing-context my-context
</pre></div> <p>If the <code class="language-plaintext highlighter-rouge">--from</code> option is not set, the <code class="language-plaintext highlighter-rouge">context</code> is created from the current context:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker context create my-context
</pre></div> <p>This can be used to create a context out of an existing <code class="language-plaintext highlighter-rouge">DOCKER_HOST</code> based script:</p> <div class="highlight"><pre class="highlight" data-language="">$ source my-setup-script.sh
$ docker context create my-context
</pre></div> <p>To source only the <code class="language-plaintext highlighter-rouge">docker</code> endpoint configuration from an existing context use the <code class="language-plaintext highlighter-rouge">--docker from=&lt;context-name&gt;</code> option. The example below creates a new context named <code class="language-plaintext highlighter-rouge">my-context</code> using the docker endpoint configuration from the existing context <code class="language-plaintext highlighter-rouge">existing-context</code> and a kubernetes configuration sourced from the file <code class="language-plaintext highlighter-rouge">/home/me/my-kube-config</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker context create \
    --docker from=existing-context \
    --kubernetes config-file=/home/me/my-kube-config \
    my-context
</pre></div> <p>To source only the <code class="language-plaintext highlighter-rouge">kubernetes</code> configuration from an existing context use the <code class="language-plaintext highlighter-rouge">--kubernetes from=&lt;context-name&gt;</code> option. The example below creates a new context named <code class="language-plaintext highlighter-rouge">my-context</code> using the kuberentes configuration from the existing context <code class="language-plaintext highlighter-rouge">existing-context</code> and a docker endpoint of <code class="language-plaintext highlighter-rouge">/var/run/docker.sock</code>:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker context create \
    --docker host=unix:///var/run/docker.sock \
    --kubernetes from=existing-context \
    my-context
</pre></div> <p>Docker and Kubernetes endpoints configurations, as well as default stack orchestrator and description can be modified with <code class="language-plaintext highlighter-rouge">docker context update</code>.</p> <p>Refer to the <a href="../context_update/index"><code class="language-plaintext highlighter-rouge">docker context update</code> reference</a> for details.</p> <h2 id="parent-command">Parent command</h2> <table> <thead> <tr> <th style="text-align: left">Command</th> <th style="text-align: left">Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left"><a href="../context/index">docker context</a></td> <td style="text-align: left">Manage contexts</td> </tr> </tbody> </table> <h2 id="related-commands">Related commands</h2> <table> <thead> <tr> <td>Command</td> <td>Description</td> </tr> </thead> <tbody> <tr> <td><a href="index">docker context create</a></td> <td>Create a context</td> </tr> <tr> <td><a href="../context_export/index">docker context export</a></td> <td>Export a context to a tar or kubeconfig file</td> </tr> <tr> <td><a href="../context_import/index">docker context import</a></td> <td>Import a context from a tar or zip file</td> </tr> <tr> <td><a href="../context_inspect/index">docker context inspect</a></td> <td>Display detailed information on one or more contexts</td> </tr> <tr> <td><a href="../context_ls/index">docker context ls</a></td> <td>List contexts</td> </tr> <tr> <td><a href="../context_rm/index">docker context rm</a></td> <td>Remove one or more contexts</td> </tr> <tr> <td><a href="../context_update/index">docker context update</a></td> <td>Update a context</td> </tr> <tr> <td><a href="../context_use/index">docker context use</a></td> <td>Set the current docker context</td> </tr> </tbody> </table> <div class="_attribution">
  <p class="_attribution-p">
    &copy; 2019 Docker, Inc.<br>Licensed under the Apache License, Version 2.0.<br>Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.<br>Docker, Inc. and other parties may also have trademark rights in other terms used herein.<br>
    <a href="https://docs.docker.com/engine/reference/commandline/context_create/" class="_attribution-link">https://docs.docker.com/engine/reference/commandline/context_create/</a>
  </p>
</div>