Skip to content

Instantly share code, notes, and snippets.

@polotek
Forked from fancyremarker/db-launch.sh
Last active April 20, 2016 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polotek/b7990b9aee9edf092095 to your computer and use it in GitHub Desktop.
Save polotek/b7990b9aee9edf092095 to your computer and use it in GitHub Desktop.
Example: db-launch script to launch the Aptible postgresql database image
# A script for creating aptible postgres databases in containers
container=$(head -c 32 /dev/urandom | md5);
username=${USERNAME:-aptible};
passphrase=${PASSPHRASE:-password};
dbname=${DATABASE:-db}
cname=${CNAME}
extport=${EXTPORT:-5432}
image="${@: -1}";
# Create a data volume
docker create --name $container $image;
# Initialize the database
docker run --rm \
--volumes-from $container \
-e USERNAME=$username \
-e PASSPHRASE=$passphrase \
-e DATABASE=$dbname \
$image --initialize;
# Run the database
cid="$(docker run -d -p $extport:5432 --name $cname --volumes-from $container $@)"
# Rename the data volume to match the database
docker rename $container "$cname-data"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment