Home Explore Blog CI



docker

1st chunk of `content/manuals/engine/manage-resources/contexts.md`
911a1a927c1b91a602f5fa16b98064068c4054bb6af5b9830000000100000c79
---
title: Docker contexts
description: Learn about managing multiple daemons from a single client with contexts
keywords: engine, context, cli, daemons, remote
aliases:
  - /engine/context/working-with-contexts/
---

## Introduction

This guide shows how you can use contexts to manage Docker daemons from a single client.

Each context contains all information required to manage resources on the daemon.
The `docker context` command makes it easy to configure these contexts and switch between them.

As an example, a single Docker client might be configured with two contexts:

- A default context running locally
- A remote, shared context

Once these contexts are configured,
you can use the `docker context use <context-name>` command
to switch between them.

## Prerequisites

To follow the examples in this guide, you'll need:

- A Docker client that supports the top-level `context` command

Run `docker context` to verify that your Docker client supports contexts.

## The anatomy of a context

A context is a combination of several properties. These include:

- Name and description
- Endpoint configuration
- TLS info

To list available contexts, use the `docker context ls` command.

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

This shows a single context called "default".
It's configured to talk to a daemon through the local `/var/run/docker.sock` Unix socket.

The asterisk in the `NAME` column indicates that this is the active context.
This means all `docker` commands run against this context,
unless overridden with environment variables such as `DOCKER_HOST` and `DOCKER_CONTEXT`,
or on the command-line with the `--context` and `--host` flags.

Dig a bit deeper with `docker context inspect`.
The following example shows how to inspect the context called `default`.

```console
$ docker context inspect default
[
    {
        "Name": "default",
        "Metadata": {},
        "Endpoints": {
            "docker": {
                "Host": "unix:///var/run/docker.sock",
                "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

Title: Managing Docker Daemons with Docker Contexts
Summary
This document introduces Docker contexts, which allow managing multiple Docker daemons from a single client. Each context contains the information to manage resources on a daemon. The document provides instructions on how to list, inspect, and create Docker contexts.