dotfiles/stowers/shell-utils/dot-local/bin/devc-ssh

27 lines
723 B
Bash
Executable file

#!/bin/bash
CONTAINER="docker"
if ! command -v docker &>/dev/null; then
CONTAINER="podman"
fi
if [[ "$#" -lt 1 ]]; then
echo "Usage: $0 <container id>" >&2
exit 1
fi
container_id="$1"; shift
# We expect a devcontainer to run an SSH server on 2222/tcp
# and to have this port exposed. We find the host binding
# to SSH to that container.
if ! ssh_port="$(${CONTAINER} inspect --format '{{ (index (index .NetworkSettings.Ports "2222/tcp") 0).HostPort }}' "${container_id}" 2>/dev/null)"; then
echo "[!] Could not get SSH host port for container '${container_id}'" >&2
exit 1
fi
ssh -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=false \
-p "${ssh_port}" \
dev@localhost "$@"