Skip to content

Commit a6d013f

Browse files
authored
Merge pull request #6840 from vibhuanand/3064-context-use-docs
docs: clarify docker context use affects all terminal sessions
2 parents 247839f + e03b837 commit a6d013f

3 files changed

Lines changed: 56 additions & 6 deletions

File tree

cli/command/context/use.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func newUseCommand(dockerCLI command.Cli) *cobra.Command {
1414
cmd := &cobra.Command{
1515
Use: "use CONTEXT",
16-
Short: "Set the current docker context",
16+
Short: "Set the default docker context",
1717
Args: cobra.ExactArgs(1),
1818
RunE: func(cmd *cobra.Command, args []string) error {
1919
name := args[0]

docs/reference/commandline/context.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Manage contexts
1515
| [`rm`](context_rm.md) | Remove one or more contexts |
1616
| [`show`](context_show.md) | Print the name of the current context |
1717
| [`update`](context_update.md) | Update a context |
18-
| [`use`](context_use.md) | Set the current docker context |
18+
| [`use`](context_use.md) | Set the default docker context |
1919

2020

2121

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,63 @@
11
# context use
22

33
<!---MARKER_GEN_START-->
4-
Set the current docker context
4+
Set the default docker context
55

66

77
<!---MARKER_GEN_END-->
88

99
## Description
1010

11-
Set the default context to use, when `DOCKER_HOST`, `DOCKER_CONTEXT` environment
12-
variables and `--host`, `--context` global options aren't set.
13-
To disable usage of contexts, you can use the special `default` context.
11+
The `docker context use` command sets the default context for the Docker CLI.
12+
13+
The `docker context use` command sets the Docker CLI’s default context by updating
14+
your CLI config (`~/.docker/config.json`). This change is persistent, affecting
15+
all shells and sessions that share that config, not just the current terminal.
16+
17+
For one-off commands or per-shell usage, use `--context` or the `DOCKER_CONTEXT`
18+
environment variable instead.
19+
20+
## Examples
21+
22+
### Set the default (sticky) context
23+
24+
This updates the CLI configuration and applies to new terminal sessions:
25+
26+
```bash
27+
$ docker context use my-context
28+
my-context
29+
30+
$ docker context show
31+
my-context
32+
```
33+
34+
### Use a context for a single command
35+
36+
Use the global `--context` flag to avoid changing the default:
37+
38+
```bash
39+
$ docker --context my-context ps
40+
```
41+
42+
### Use a context for the current shell session
43+
44+
Set `DOCKER_CONTEXT` to override the configured default in the current shell:
45+
46+
```bash
47+
$ export DOCKER_CONTEXT=my-context
48+
$ docker context show
49+
my-context
50+
```
51+
52+
To stop overriding:
53+
54+
```bash
55+
$ unset DOCKER_CONTEXT
56+
```
57+
58+
### Switch back to the default context
59+
60+
```bash
61+
$ docker context use default
62+
default
63+
```

0 commit comments

Comments
 (0)