Skip to content

Instantly share code, notes, and snippets.

@shtirlic
Forked from bhyde/get-docker-socket-from-remote
Last active September 22, 2015 11:34
Show Gist options
  • Save shtirlic/8d797407992779a80498 to your computer and use it in GitHub Desktop.
Save shtirlic/8d797407992779a80498 to your computer and use it in GitHub Desktop.
#!/bin/bash
# get-docker-socket-from-remote <name> <user>@<host>
# Create a unix socket at /tmp/<name>-docker.sock which, when
# used will ssh to <user>@<host> and connect to the docker
# socket at <host>:///var/run/docker.sock
# Note:
# 1. This forks a subjob that manages the local socket.
# Rmember to kill that when your finished
# 2. It doesn't clean up the file handle when you kill that job.
# 3. You will probably need to install socat on both ends
# -- on the mac you might do: brew install socat
# -- on <host> you might do: apt-get -y install socat
# 4. Prints a suggested means to set your DOCKER_HOST env.
# 5. Arrange to have your ssh key in the authorized keys of
# the other end, and of course have an ssh-agent on the
# local end.
NAME=$1
REMOTE=$2
echo export DOCKER_HOST=unix:///tmp/${NAME}-docker.sock
socat \
"UNIX-LISTEN:/tmp/${NAME}-docker.sock,reuseaddr,fork" \
"EXEC:'ssh -kTax $REMOTE socat STDIO UNIX-CONNECT\:/var/run/docker.sock'" \
&
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment