Skip to content

Commit d97bd28

Browse files
committed
docs: clarify docker context use is sticky
Signed-off-by: Vibhu <vibhuanand@outlook.com>
1 parent ddb9864 commit d97bd28

1 file changed

Lines changed: 43 additions & 6 deletions

File tree

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
11
# context use
22

3-
<!---MARKER_GEN_START-->
4-
Set the current docker context
3+
Set the default context for the Docker CLI.
54

5+
## Usage
66

7-
<!---MARKER_GEN_END-->
7+
docker context use CONTEXT
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+
`docker context use` sets the **default context** for the Docker CLI.
12+
13+
This command updates the Docker CLI configuration (the `currentContext` field in the client configuration file, typically `~/.docker/config.json`). Because it's a configuration change, it is **sticky** and affects **all terminal sessions** that use the same Docker CLI config directory.
14+
15+
To change the context only for a single command, or only for your current shell session, use `--context` or the `DOCKER_CONTEXT` environment variable instead.
16+
17+
## Examples
18+
19+
### Set the default (sticky) context
20+
21+
This updates the CLI configuration and applies to new terminal sessions:
22+
23+
$ docker context use chocolate
24+
chocolate
25+
26+
$ docker context show
27+
chocolate
28+
29+
### Use a context for a single command
30+
31+
Use the global `--context` flag to avoid changing the default:
32+
33+
$ docker --context chocolate ps
34+
35+
### Use a context for the current shell session
36+
37+
Set `DOCKER_CONTEXT` to override the configured default in the current shell:
38+
39+
$ export DOCKER_CONTEXT=chocolate
40+
$ docker context show
41+
chocolate
42+
43+
To stop overriding:
44+
45+
$ unset DOCKER_CONTEXT
46+
47+
### Switch back to the default context
48+
49+
$ docker context use default
50+
default

0 commit comments

Comments
 (0)