#!/bin/bash dockerRemoveApp() { local app_name="$1" if [[ -z "$app_name" ]]; then isNotice "No app name provided. Unable to stop and remove containers." fi isNotice "Stopping and removing Docker containers for '$app_name'. Please wait..." # Stop and remove containers in one go # Scope by compose project, NOT by name. `docker ps -f name=` is a # SUBSTRING match, so with multi-instance apps the base app's name is a prefix # of every instance of it: `name=bookstack` also matched bookstack_home and # bookstack_test (and their -db containers), so an operation aimed at one app # silently hit all of its instances. Each app and instance is its own compose # project (named for its directory), so the project label addresses exactly # the containers that belong to this app and nothing else. local result; result=$(dockerCommandRun "docker ps -aq --filter label=com.docker.compose.project=$app_name | xargs -r docker stop" >/dev/null 2>&1) checkSuccess "Stopped Docker containers matching '$app_name'" local result; result=$(dockerCommandRun "docker ps -aq --filter label=com.docker.compose.project=$app_name | xargs -r docker rm" >/dev/null 2>&1) checkSuccess "Removed Docker containers matching '$app_name'" }