Skip to content
Latchkey

docker context Command Reference

Manage and switch between Docker daemon endpoints.

docker context stores connection settings for Docker daemons, letting the CLI target a remote host (over SSH or TCP) instead of the local socket. In CI it is used to build or deploy against a remote Docker host without exporting DOCKER_HOST manually.

Common subcommands

  • docker context create NAME --docker host=... - define an endpoint
  • docker context use NAME - make a context the default
  • docker context ls - list contexts and show the active one
  • docker context rm NAME - remove a context
  • docker --context NAME ... - run a single command against a context

Example

shell
docker context create deploy --docker "host=ssh://ci@10.0.0.5"
docker --context deploy compose up -d

In CI

Use a context to deploy to a remote Docker host over SSH from the pipeline, keeping the connection config out of every command. Prefer --context per-command over a global use so parallel steps do not fight over the active context. DOCKER_HOST achieves the same for a single endpoint.

Key takeaways

  • Contexts point the CLI at remote daemons over SSH or TCP.
  • Prefer --context per command over a global use in shared pipelines.
  • DOCKER_HOST is the env-var equivalent for a single remote endpoint.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →