Skip to content

Instantly share code, notes, and snippets.

@andgineer
Last active July 10, 2020 06:38
Show Gist options
  • Select an option

  • Save andgineer/fcdb877eb0033234e98b3619d2267b4e to your computer and use it in GitHub Desktop.

Select an option

Save andgineer/fcdb877eb0033234e98b3619d2267b4e to your computer and use it in GitHub Desktop.
Check if a docker-compose service is running
#! /usr/bin/env bash
#
# Check if the $1 docker-compose service is running
#
# Usage:
# is_container_running <service name>
#
function container_is_not_running {
if [[ -z `docker ps -q --no-trunc | grep $(docker-compose ps -q $1)` ]]; then
echo "$1 service is not running."
return 0 # success EXIT code
else
return 1
fi
}
@andgineer

andgineer commented Jul 9, 2020

Copy link
Copy Markdown
Author
source container_is_not_running.sh  # load the function

if container_is_not_running postgres ; then
    echo
    echo "Postgres is not running!"
    echo
    exit
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment