Skip to content

Instantly share code, notes, and snippets.

@LeZuse
Created April 4, 2023 13:43
Show Gist options
  • Save LeZuse/dfd1e4ca1fd9d04e44092da92403db21 to your computer and use it in GitHub Desktop.
Save LeZuse/dfd1e4ca1fd9d04e44092da92403db21 to your computer and use it in GitHub Desktop.
Quickly start psql REPL with a fresh PostgreSQL instance
# 1. Launch Docker Desktop
# 2. Verify it is running:
docker ps
# 3. Start up a postgres instance and grab the container ID:
container_id=$(docker run -e POSTGRES_PASSWORD=mysecretpassword -d postgres)
# 4. Connect using psql:
docker exec -it "$container_id" psql -h localhost -U postgres
# 5. After doing your business, exit psql and shutdown the instance:
docker stop $container_id
# 6. Cleanup if you won't be using the instance anymore
docker rm $container && docker volume prune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment