Here you can find some useful commands for running PostgreSQL in Docker
container and connect to it via psql or pgcli. You can use it for study
PostgreSQL or whatever you want.
docker run --rm --name sql-test -v sql_test:/var/lib/postgresql/data -p 5433:5432 -d postgres:10-alpine
docker exec -it sql-test psql -U postgres
For using Postgres CLI (http://pgcli.com) you need to:
- Install pgcli (see https://github.com/dbcli/pgcli)
- Run the following command
$ pgcli -h localhost -p 5432 -U postgres
Don't forget to stop docker container when your work is finished:
$ docker stop $(docker ps -a -q)
Instead of commands above you can simply run: make psql, make pgcli or
make stop
Before starting, you need to have Docker installed