Created
April 4, 2023 13:43
-
-
Save LeZuse/dfd1e4ca1fd9d04e44092da92403db21 to your computer and use it in GitHub Desktop.
Quickly start psql REPL with a fresh PostgreSQL instance
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
# 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