Docker Remote Context via SSH over Proxy
Source: Dev.to
Overview
Securely manage a remote Docker daemon over SSH using Docker contexts, with SSH traffic routed through a SOCKS5 proxy.
By configuring SSH to use a proxy and defining a Docker context that targets the remote host via SSH, Docker commands executed locally are transparently forwarded to the remote Docker daemon. This lets you use standard Docker workflows (docker ps, docker compose, docker build) as if the daemon were local, while still benefiting from:
- SSH key authentication
- Proxy enforcement (SOCKS5 or HTTP)
- Connection keep‑alive mechanisms
SSH Configuration
Add a host pattern to ~/.ssh/config so that any matching host uses the proxy and keep‑alive settings automatically.
# Apply to all hosts matching vps-*
Host vps-*
ServerAliveInterval 10
ProxyCommand nc --proxy-type socks5 --proxy 127.0.0.1:10808 %h %p
# Specific host for Docker access
Host vps-docker
HostName
User
Port
PreferredAuthentications publickey
- ServerAliveInterval – Sends periodic packets to keep the SSH connection alive.
- ProxyCommand – Forces SSH traffic through a local SOCKS5 proxy (e.g., a VPN tunnel).
- PreferredAuthentications publickey – Enforces public‑key authentication instead of password authentication.
Docker Context
Create a Docker context that connects to the remote daemon over SSH:
docker context create vps-docker-host --docker "host=ssh://vps-docker"
Activate the context:
docker context use vps-docker-host
With the context active, all Docker CLI commands (docker ps, docker compose, docker build, etc.) operate against the remote Docker daemon instead of the local one.