|
1 | 1 | # context use |
2 | 2 |
|
3 | 3 | <!---MARKER_GEN_START--> |
4 | | -Set the current docker context |
| 4 | +Set the default docker context |
5 | 5 |
|
6 | 6 |
|
7 | 7 | <!---MARKER_GEN_END--> |
8 | 8 |
|
9 | 9 | ## Description |
10 | 10 |
|
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