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 参考。