Created
November 25, 2015 19:54
-
-
Save jrforrest/c31a557620855efe1606 to your computer and use it in GitHub Desktop.
Docker remote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.