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 endpointdocker context use NAME- make a context the defaultdocker context ls- list contexts and show the active onedocker context rm NAME- remove a contextdocker --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 -dIn 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
docker buildx create and use Command ReferenceReference for docker buildx create and docker buildx use in CI: provision a builder instance with the docker-…
docker compose up Command ReferenceReference for docker compose up in CI: start services from a compose file with -d, --build, and --wait so dep…
docker run Command ReferenceReference for docker run in CI: --rm, -e, -v, --network, -w, and --entrypoint flags for creating and starting…