Commit feda7f63 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 b2ec8c03
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
#!/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"