-
-
Save polotek/b7990b9aee9edf092095 to your computer and use it in GitHub Desktop.
Example: db-launch script to launch the Aptible postgresql database image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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