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 参考 以获取详细信息。