docker-scripts/docker-node

17 lines
439 B
Plaintext
Raw Permalink Normal View History

2023-02-08 19:46:00 +00:00
#!/bin/bash
# this command helper depends on key-based (passwordless) SSH access by the current user to each of the docker swarm nodes.
NODE_HOST=$1; shift;
nc -zvw3 $NODE_HOST 22 &> /dev/null;
PING_RESULT=$?
if [ $PING_RESULT != 0 ]; then
echo
echo "Host '$NODE_HOST' not reachable."
exit 2
fi
# connect to the docker host through SSH
export DOCKER_HOST="ssh://$(whoami)@$NODE_HOST.$(hostname -d)"
# execute the command
docker $@