docker context create
| 描述 | 建立上下文 |
|---|---|
| 用法 | docker context create [OPTIONS] CONTEXT |
描述
建立一個新的 context。這允許您切換 docker CLI 連線到的守護程式。
選項
示例
使用 Docker 端點建立上下文 (--docker)
使用 --docker 標誌建立具有自定義端點的上下文。以下示例建立一個名為 my-context 的上下文,其 docker 端點為 /var/run/docker.sock
$ docker context create \
--docker host=unix:///var/run/docker.sock \
my-context
基於現有上下文建立上下文 (--from)
使用 --from=<context-name> 選項從現有上下文建立新上下文。以下示例從現有上下文 existing-context 建立一個名為 my-context 的新上下文
$ docker context create --from existing-context my-context
如果未設定 --from 選項,則 context 將從當前上下文建立
$ docker context create my-context
這可用於從現有的基於 DOCKER_HOST 的指令碼建立上下文
$ source my-setup-script.sh
$ docker context create my-context
要從現有上下文獲取 docker 端點配置,請使用 --docker from=<context-name> 選項。以下示例使用現有上下文 existing-context 的 docker 端點配置建立一個名為 my-context 的新上下文
$ docker context create \
--docker from=existing-context \
my-context
Docker 端點配置以及描述可以透過 docker context update 進行修改。
有關詳細資訊,請參閱 docker context update 參考。