Home Explore Blog CI



docker

2nd chunk of `content/manuals/engine/manage-resources/contexts.md`
0d0730bcfcb3872db611d090b815d03d36937c948d3e3295000000010000082b
                "SkipTLSVerify": false
            }
        },
        "TLSMaterial": {},
        "Storage": {
            "MetadataPath": "\u003cIN MEMORY\u003e",
            "TLSPath": "\u003cIN MEMORY\u003e"
        }
    }
]
```

### Create a new context

You can create new contexts with the `docker context create` command.

The following example creates a new context called `docker-test` and specifies
the host endpoint of the context to TCP socket `tcp://docker:2375`.

```console
$ docker context create docker-test --docker host=tcp://docker:2375
docker-test
Successfully created context "docker-test"
```

The new context is stored in a `meta.json` file below `~/.docker/contexts/`.
Each new context you create gets its own `meta.json` stored in a dedicated sub-directory of `~/.docker/contexts/`.

You can view the new context with `docker context ls` and `docker context inspect <context-name>`.

```console
$ docker context ls
NAME          DESCRIPTION                             DOCKER ENDPOINT               ERROR
default *                                             unix:///var/run/docker.sock
docker-test                                           tcp://docker:2375
```

The current context is indicated with an asterisk ("\*").

## Use a different context

You can use `docker context use` to switch between contexts.

The following command will switch the `docker` CLI to use the `docker-test` context.

```console
$ docker context use docker-test
docker-test
Current context is now "docker-test"
```

Verify the operation by listing all contexts and ensuring the asterisk ("\*") is against the `docker-test` context.

```console
$ docker context ls
NAME            DESCRIPTION                           DOCKER ENDPOINT               ERROR
default                                               unix:///var/run/docker.sock
docker-test *                                         tcp://docker:2375
```

`docker` commands will now target endpoints defined in the `docker-test` context.

You can also set the current context using the `DOCKER_CONTEXT` environment variable.

Title: Creating and Using Docker Contexts
Summary
This section details how to create a new Docker context using the `docker context create` command, specifying the host endpoint. It also demonstrates how to switch between contexts using `docker context use`, making the Docker CLI target the endpoints defined in the selected context. Additionally, it mentions using the `DOCKER_CONTEXT` environment variable to set the current context.