Update src/dockerutils.sh

This commit is contained in:
colin 2024-07-24 03:21:20 +00:00
parent d0c6d89996
commit f209d5c0c9
1 changed files with 28 additions and 1 deletions

View File

@ -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 <container-name>"
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