docker: Remote hosts over SSH
The docker
CLI tool usually connects to the local docker daemon but can also connect to remote daemons. DOCKER_HOST
and "contexts" can both be used to achieve that, and both respect local SSH config.
First configure SSH to allow passwordless connection to the remote host using keys i.e. allow connection using ssh remote-1
.
Then either use DOCKER_HOST
:
DOCKER_HOST="ssh://remote-1" docker ps # single command
Or create and use a docker context:
docker context create remote-1 --docker "host=ssh://remote-1"
docker --context remote-1 ps # single command
docker context use remote-1 # default for commands
docker ps
Published on: 29 Mar 2023