Skip to content

Instantly share code, notes, and snippets.

@en0
Created May 24, 2015 06:07
Show Gist options
  • Save en0/392517ca5b798a5d0726 to your computer and use it in GitHub Desktop.
Save en0/392517ca5b798a5d0726 to your computer and use it in GitHub Desktop.
A quick wrapper for running docker containers
#!/usr/bin/env bash
# Look for existing instances
CID=$(docker ps -a -f name=$CNAME -q)
if [ ! -z "${CID}" ]
then
# Determin if the instance is already running
IS_RUNNING=$(docker inspect --format='{{.State.Running}}' $CID)
if [ "${IS_RUNNING}" == "true" ]
then
# Already running.
echo "Service is already up"
else
# Not running but exists, Restart it.
echo "Starting existing service instance."
docker start $CID
exit $?
fi
else
# No instance found. Start a new one.
start_docker
fi
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment