Last active
December 13, 2025 19:14
-
-
Save rpsirois/a3901e5d43b81e4ae1d20d65a8a8cebc 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 bash | |
| dkr-env-clear() { | |
| export DOCKER_TLS_VERIFY="" | |
| export DOCKER_HOST="" | |
| export DOCKER_CERT_PATH="" | |
| export DOCKER_MACHINE_NAME="" | |
| } | |
| dkr-env() { dkr-env-remote $* } | |
| 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 -i $1 -nNT -L $UNIXSOCK:/var/run/docker.sock $2 & | |
| else | |
| echo | |
| echo "Usage: " | |
| echo | |
| echo " dkr-env-remote ssh_key_path user@«destination»" | |
| echo | |
| fi | |
| } | |
| dkr-images-flat() { | |
| docker image ls --format "{{.Repository}}:{{.Tag}}" | |
| } | |
| export -f dkr-env-clear | |
| export -f dkr-env | |
| export -f dkr-env-remote | |
| export -f dkr-images-flat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment