Skip to content
Snippets Groups Projects
Commit a5a3b85e authored by nimrod's avatar nimrod
Browse files

Add docker remote sub-command.

Add the docker remote sub-command (actually the _docker-remote script
but can be invoked as a sub-command with the wrapper script). It creates
a local socket that's forwarded to the dockerd socket on the remote host
via ssh. Requires OpenSSH 6.7 or later (for Unix socket forwarding and
%C token. Typical invocation would be `$(docker remote
host.domain.example)`. A blog post will follow.
parent c06aae22
No related branches found
No related tags found
No related merge requests found
#!/bin/sh
set -eu
[ -n "$1" ] || { echo "You must specify host." >> /dev/stderr; exit 1; }
host="$1"
localsocket="$HOME/.ssh/docker_$host.sock"
ssh="ssh -fnNTS ~/.ssh/%C.sock"
# Check for exiting forward
if ! $ssh -O check -L "$localsocket:/var/run/docker.sock" "$host" 2> /dev/null
then
# Delete socket if it exists
[ ! -S "$localsocket" ] || rm "$localsocket"
# Open SSH ControlMaster
$ssh -o ExitOnForwardFailure=no -o ControlMaster=auto -o ControlPersist=0 "$host"
# Forward socket
$ssh -O forward -L "$localsocket:/var/run/docker.sock" "$host"
fi
# Echo the DOCKER_HOST export command, for eval'ing.
echo "export DOCKER_HOST=unix://$localsocket"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment