🐳 Docker Intermediate

What is Docker context?

Why Interviewers Ask This

This question targets practical, hands-on experience with Docker. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.

Answer

A Docker context stores the connection configuration needed to connect to a Docker daemon — the endpoint, authentication, and TLS certificates. Docker uses contexts to switch between different Docker environments (local, remote server, Docker Desktop, cloud) without reconfiguring environment variables. Default context: default — connects to the local Docker daemon via /var/run/docker.sock. Commands: docker context ls — list all contexts; docker context use production-server — switch active context; docker context create remote-server --docker "host=ssh://user@server.com" — create SSH-based remote context; docker context inspect contextname — inspect context details. When you switch context, all Docker commands (docker ps, docker run, docker build) execute against that environment. Use cases: (1) Manage multiple remote Docker hosts from your local machine; (2) Switch between Docker Desktop (dev) and a remote Docker host (staging); (3) Docker Desktop creates contexts for different engines (Windows/Linux containers); (4) Used by Docker Compose — DOCKER_CONTEXT env var. With buildx, contexts enable building on remote build machines. SSH context creates an SSH tunnel automatically — no need to expose the Docker daemon socket over TCP (which should be protected with TLS or kept local).

Common Mistake

A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.