Last active
August 29, 2015 14:22
-
-
Save josmardias/43dc5af52351367e36e5 to your computer and use it in GitHub Desktop.
create postgres docker container
This file contains hidden or 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
#!/usr/bin/env bash | |
VOLUME_NAME="test-postgres-data" | |
CONTAINER_NAME="test-postgres9.4" | |
PGPASSWORD="password" | |
DATABASE="test" | |
( | |
echo -e "\ncreating persistent volume...\n"; | |
docker create -v /var/lib/postgresql/data --name $VOLUME_NAME busybox | |
) && | |
( | |
echo -e "\ncreating named container...\n"; | |
docker run --name $CONTAINER_NAME -p 5432:5432 -e POSTGRES_PASSWORD=$PGPASSWORD -d --volumes-from $VOLUME_NAME docker.io/postgres | |
) && | |
( | |
echo -e "\ncreating database...\n" | |
docker run -e "PGPASSWORD=$PGPASSWORD" -e "DATABASE=$DATABASE" -it --link $CONTAINER_NAME:postgres --rm docker.io/postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres --command "CREATE DATABASE $DATABASE;"' | |
) && | |
echo "container $CONTAINER_NAME created and running" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment