Skip to content

Instantly share code, notes, and snippets.

@richardolsson
Created March 16, 2015 08:04
Show Gist options
  • Save richardolsson/a7f78c7ad85a11b64990 to your computer and use it in GitHub Desktop.
Save richardolsson/a7f78c7ad85a11b64990 to your computer and use it in GitHub Desktop.
up.sh - Simplified Docker Compose replacement
#!/bin/sh
build_if_not_exists() {
# Param $1: name of image
# Param $2: path to build context
images=`docker images |grep -e ^$1[[:space:]]`
if [ -z "$images" ]; then
echo building $1
docker build -t $1 $2
else
echo $1 already built
fi
}
run_container() {
# Param $1: name of image/container
# Param $2: command line args
echo starting $1
docker run --name=$1 $2 $1
}
container_up() {
# Param $1: name of image/container
# Param $2: command line args
running=`docker inspect -f "{{.State.Running}}" $1`
if [ $? = 0 ]; then
if [ "$running" = "true" ]; then
echo "skipping $1 (already running)"
else
if [ "$running" = "false" ]; then
echo removing old $1
docker rm -f $1 2>&1 > /dev/null
fi
run_container $1 "$2"
fi
else
run_container $1 "$2"
fi
}
build_if_not_exists db database
container_up db "-d"
container_up redis "-d"
build_if_not_exists api api
container_up api "-ti --link db:db --link redis:redis -v $PWD/..:/var/zetkin-platform -p 8080:8080"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment