Home Explore Blog CI



docker

3rd chunk of `content/manuals/engine/manage-resources/contexts.md`
a1e7cedcb4b313daa31695e52ae12a116a3d2e32c809e42f0000000100000c4d
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.
The environment variable overrides the context set with `docker context use`.

Use the appropriate command below to set the context to `docker-test` using an environment variable.

{{< tabs >}}
{{< tab name="PowerShell" >}}

```ps
> $env:DOCKER_CONTEXT='docker-test'
```

{{< /tab >}}
{{< tab name="Bash" >}}

```console
$ export DOCKER_CONTEXT=docker-test
```

{{< /tab >}}
{{< /tabs >}}

Run `docker context ls` to verify that the `docker-test` context is now the
active context.

You can also use the global `--context` flag to override the context.
The following command uses a context called `production`.

```console
$ docker --context production container ls
```

## Exporting and importing Docker contexts

You can use the `docker context export` and `docker context import` commands
to export and import contexts on different hosts.

The `docker context export` command exports an existing context to a file.
The file can be imported on any host that has the `docker` client installed.

### Exporting and importing a context

The following example exports an existing context called `docker-test`.
It will be written to a file called `docker-test.dockercontext`.

```console
$ docker context export docker-test
Written file "docker-test.dockercontext"
```

Check the contents of the export file.

```console
$ cat docker-test.dockercontext
```

Import this file on another host using `docker context import`
to create context with the same configuration.

```console
$ docker context import docker-test docker-test.dockercontext
docker-test
Successfully imported context "docker-test"
```

You can verify that the context was imported with `docker context ls`.

The format of the import command is `docker context import <context-name> <context-file>`.

## Updating a context

You can use `docker context update` to update fields in an existing context.

The following example updates the description field in the existing `docker-test` context.

```console
$ docker context update docker-test --description "Test context"
docker-test
Successfully updated context "docker-test"
```

Title: Switching, Exporting, Importing, and Updating Docker Contexts
Summary
This section explains how to switch between Docker contexts using `docker context use` and the `DOCKER_CONTEXT` environment variable. It covers exporting and importing contexts with `docker context export` and `docker context import` for transferring context configurations. Finally, it shows how to update a context using `docker context update` to modify fields like the description.