Quick Flow
# 현재 target 확인
docker context ls
docker context inspect default
# SSH endpoint를 가진 context 생성
docker context create staging --docker host=ssh://deploy@staging.example.com
# 일회성 명령은 context를 명시
docker --context staging container ls --all
# 필요할 때만 shell 전체의 기본 context 전환
docker context use stagingcontext는 daemon endpoint, TLS material, description을 묶습니다. active context가 바뀌면 같은 docker ps, docker compose down, docker volume rm도 다른 daemon에 적용되므로 destructive command는 --context <name>으로 대상을 드러내는 편이 안전합니다.
실행 대상
docker context ls의 *는 active context입니다. context는 local Unix socket, Docker Desktop, SSH remote daemon, TLS-protected TCP endpoint 등 Docker API 연결 정보를 보관합니다. context 자체가 remote host의 image·volume·network를 복제하거나 동기화하는 기능은 아닙니다.
docker context ls
docker context inspect staging
docker --context staging infodocker context use staging은 이후 shell의 기본 대상을 바꾸고, DOCKER_CONTEXT environment variable은 이 기본값을 override합니다. docker --context staging ... 같은 command-line option은 현재 명령만 명시적으로 override합니다. CI와 incident command에는 implicit active context보다 명시 option을 우선합니다.
remote daemon 보안
remote Docker API를 제어할 수 있으면 그 daemon host에서 image build, privileged container, host mount, network 설정을 수행할 수 있습니다. SSH context는 SSH authentication·host verification을 사용해 remote socket에 연결하는 방식이라, plain TCP daemon port를 노출하는 것보다 안전한 기본 선택입니다.
docker context create production \
--description 'production daemon via SSH' \
--docker host=ssh://deploy@prod.example.comtcp://0.0.0.0:2375처럼 인증·encryption 없는 daemon listener는 remote root-equivalent control surface를 network에 노출할 수 있습니다. TCP endpoint가 꼭 필요하면 TLS client certificate, firewall allowlist, least-privileged access, audit logging을 host policy로 함께 구성합니다.
remote 작업의 경계
context가 remote면 bind mount source path, local image cache, docker compose up의 project resource는 remote daemon host 기준입니다. local laptop의 $PWD를 mount한다고 생각했는데 remote host의 path가 없어 실패하거나, local에서 봤던 image tag가 remote에는 없는 문제가 생길 수 있습니다.
# remote host의 image·volume 목록을 봄
docker --context staging image ls
docker --context staging volume ls
# context export에는 endpoint와 TLS material이 들어갈 수 있음
docker context export stagingcontext export file은 endpoint·TLS material을 포함할 수 있으므로 secret처럼 다룹니다. context를 공유할 때는 target host 범위, SSH account 권한, certificate rotation, context file 보관 위치까지 확인합니다.
context 전환은 UI profile 선택이 아니라 command의 실행 host를 바꾸는 일입니다. production context에서 compose down, system prune, volume rm을 실행하기 전에는 docker --context production info로 daemon identity와 대상 resource를 먼저 확인하십시오.
참고 링크
2 sources