From f209d5c0c9f6930a9acbe75a1339dac25bb85400 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 24 Jul 2024 03:21:20 +0000 Subject: [PATCH] Update src/dockerutils.sh --- src/dockerutils.sh | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/dockerutils.sh b/src/dockerutils.sh index 659a0b9..ff666ea 100644 --- a/src/dockerutils.sh +++ b/src/dockerutils.sh @@ -11,6 +11,7 @@ check_swarm_status() { echo "Node is in an active swarm." else echo "Node swarm status is unknown: $SWARM_STATUS" + echo "Usage: Ensure Docker is running and the node is part of a swarm." return 1 fi } @@ -23,6 +24,10 @@ check_node_role() { else echo "Node is a worker." fi + if [ -z "$NODE_ROLE" ]; then + echo "Usage: Ensure Docker is running and the node is part of a swarm." + return 1 + fi } # Function to list Docker volumes @@ -34,6 +39,10 @@ list_docker_volumes() { echo "Available Docker volumes:" echo "$volumes" fi + if [ $? -ne 0 ]; then + echo "Usage: Ensure Docker is running and you have the correct permissions." + return 1 + fi } # Function to list Docker overlay networks @@ -45,6 +54,10 @@ list_docker_overlay_networks() { echo "Docker overlay networks:" echo "$networks" fi + if [ $? -ne 0 ]; then + echo "Usage: Ensure Docker is running and you have the correct permissions." + return 1 + fi } # Function to deploy a Docker stack with registry auth @@ -54,6 +67,10 @@ dup() { return 1 fi docker stack deploy --with-registry-auth -c ~/"$1"/"$1".yml "$1" + if [ $? -ne 0 ]; then + echo "Usage: Ensure the stack name is correct and the Docker Compose file exists in the specified location." + return 1 + fi } # Function to remove a Docker stack @@ -63,6 +80,10 @@ ddn() { return 1 fi docker stack rm "$1" + if [ $? -ne 0 ]; then + echo "Usage: Ensure the stack name is correct and the Docker stack is currently deployed." + return 1 + fi } # Function to get container ID by name @@ -71,7 +92,13 @@ cid() { echo "Usage: cid " return 1 fi - docker ps -qf "name=^$1" 2>/dev/null + container_id=$(docker ps -qf "name=^$1" 2>/dev/null) + if [ -z "$container_id" ]; then + echo "No container found with the name: $1" + echo "Usage: Ensure the container name is correct and the container is running." + return 1 + fi + echo "$container_id" } # Export functions as commands