Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Docker remote
#!/bin/sh
# Connects to remote docker instances via ssh
# USAGE:
# CONNECT: docker-remote connect user@ssh-server
# DISCONNECT: docker-remote disconnect
# RUN COMMAND: docker-remote <docker cmd>
set -m #shell must support job control
SOCK_PATH=/tmp/docker_remote.sock
LOGFILE_PATH=/tmp/docker_remote.log
PID_PATH=/tmp/docker_remote.pid
if [ "$1" = "connect" ]; then
server=$2
if [ -z $server ]; then
echo "Server must be specified" >&2
exit 1
fi
if [ -f "$PID_PATH" ]; then
echo "Server appears to already be running! \`docker-remote stop\` first."
fi
nohup socat "UNIX-LISTEN:$SOCK_PATH,reuseaddr,fork" \
EXEC:"ssh $server socat STDIO UNIX-CONNECT\:/var/run/docker.sock" \
1>$LOGFILE_PATH 2>$LOGFILE_PATH &
echo $! > $PID_PATH
elif [ "$1" = "disconnect" ]; then
pid=`cat $PID_PATH`
if [ -z $pid ]; then
echo "No pid found in pidfile: $PID_PATH" &>2
exit 1
fi
kill `cat $PID_PATH`
rm $PID_PATH
rm $SOCK_PATH
else
docker -H unix://$SOCK_PATH $@
fi
@jrforrest

This comment has been minimized.

Copy link
Owner Author

commented Nov 25, 2015

This just forwards docker commands to a local socket via ssh connections to a remote host. It is not very quick, and the script is brittle, but it does in a pinch when you want to do remote docker builds without setting up SSL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.