Created
January 18, 2020 19:45
-
-
Save kendru/bf34eafc0582f81a6a58150d8ddb3519 to your computer and use it in GitHub Desktop.
Set up a throw-away postgresql server in docker and a client to connect to it
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
#!/bin/bash | |
docker pull postgres:11-alpine | |
docker network inspect postgres_sandbox > /dev/null 2>&1 | |
if [[ "$?" == "0" ]]; then | |
docker network rm postgres_sandbox | |
fi | |
docker network create --driver bridge postgres_sandbox | |
docker run -d --name postgres_server --network postgres_sandbox --health-cmd='pg_isready' -e POSTGRES_PASSWORD=s3cr3t postgres:11-alpine | |
printf "Waiting for Postgres to start" | |
while [ $(docker inspect --format "{{json .State.Health.Status }}" postgres_server) != "\"healthy\"" ]; do | |
printf "." | |
sleep 1 | |
done | |
printf "\nServer started. Connecting.\n" | |
docker run -it --rm --name postgres_client --network postgres_sandbox -e PGPASSWORD=s3cr3t postgres:11-alpine psql -h postgres_server -U postgres | |
docker stop postgres_server && docker rm postgres_server | |
docker network rm postgres_sandbox |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment