Last active
December 13, 2025 19:14
-
-
Save rpsirois/6643916678a3da0d5111b5ed336e0efe to your computer and use it in GitHub Desktop.
This script sets up a non-interactive SSH tunnel (-nNT, no shell, no TTY, no stdin) that forwards a remote Docker daemon’s Unix socket to a local socket, allowing local Docker commands to control the remote host without opening a remote shell.
This file contains hidden or 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
| #!/usr/bin/env zsh | |
| function dkr-env-clear() { | |
| export DOCKER_TLS_VERIFY="" | |
| export DOCKER_HOST="" | |
| export DOCKER_CERT_PATH="" | |
| export DOCKER_MACHINE_NAME="" | |
| } | |
| function dkr-env() { dkr-env-remote $* } | |
| function dkr-env-remote() { | |
| if [[ -n "$1" ]] ; then | |
| local UNIXSOCK="$(mktemp)-docker.sock" | |
| export DOCKER_HOST="unix://${UNIXSOCK}" | |
| echo DOCKER_HOST=$DOCKER_HOST | |
| echo "ssh -i $1 -nNT -L $UNIXSOCK:/var/run/docker.sock $2 &" | |
| ssh -nNT -L $UNIXSOCK:/var/run/docker.sock $2 & | |
| else | |
| echo | |
| echo "Usage: " | |
| echo | |
| echo " dkr-env-remote ssh_key_path user@«destination»" | |
| echo | |
| fi | |
| } | |
| function dkr-images-flat() { | |
| docker image ls --format "{{.Repository}}:{{.Tag}}" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment