| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!/bin/bash
- # Script to shut down a list of Docker containers in non-interactive mode
- # Array of container IDs or names (modify this array as needed)
- CONTAINERS=(
- "nc8"
- "nc8_govod"
- "nc8_cron"
- "nc8_db"
- "nc8_es"
- "nc8_clamav"
- "nc8_onlyoffice"
- "nc8_redis"
- )
- # Function to check if a command was successful
- check_status() {
- if [ $? -ne 0 ]; then
- echo "Error: $1 failed. Exiting."
- exit 1
- fi
- }
- # Step 1: Process each container in the array
- if [ ${#CONTAINERS[@]} -gt 0 ]; then
- echo "Processing specified containers..."
- for CONTAINER in "${CONTAINERS[@]}"; do
- # Check if the container exists
- echo "Checking if container '$CONTAINER' exists..."
- docker ps -a --filter "name=$CONTAINER" --format '{{.Names}}' | grep -q "^$CONTAINER$"
- if [ $? -ne 0 ]; then
- echo "Warning: Container '$CONTAINER' does not exist. Skipping."
- continue
- fi
- # Stop the container
- echo "Stopping container '$CONTAINER'..."
- docker stop "$CONTAINER"
- check_status "Stopping container '$CONTAINER'"
- # Remove the container
- #echo "Removing container '$CONTAINER'..."
- #docker rm "$CONTAINER"
- #check_status "Removing container '$CONTAINER'"
- done
- else
- echo "Error: No containers specified in the array. Exiting."
- exit 1
- fi
- echo "All specified containers have been successfully shut down and removed."
|