paolodenti / psqlclient

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PSQL Client as Docker image

Build and Push

Postgresql client, interactive, or to run a single script or execute file content.

Interactive CLI

docker run --rm -it --network host \
  paolodenti/psqlclient \
  psql postgresql://<username>:<password>@<host>:<port>/<db name>

Execute a sql command

# execute \dt;
docker run --rm --network host \
  paolodenti/psqlclient \
  psql postgresql://<username>:<password>@<host>:<port>/<db name> \
  -c "\dt;"

Execute a sql file

# prepare a sample sql commands file
cat <<EOT >> commands.sql
\dt;
EOT

# execute the commands in the file
docker run --rm --network host \
  -v $(pwd)/commands.sql:/commands.sql \
  paolodenti/psqlclient \
  psql postgresql://<username>:<password>@<host>:<port>/<db name> \
  -f /commands.sql

Connect to an existing docker compose postgres instance

docker network ls
# find out the compose network name

docker run --rm -it --network <the compose network> \
  paolodenti/psqlclient \
  psql postgresql://<username>:<password>@<the compose service name>:<port>/<db name>

Configure psqlclient as a standard psql command

alias psql='docker run --rm -it --network host paolodenti/psqlclient psql'

psql postgresql://<username>:<password>@<host>:<port>/<db name>
# or
psql -h <host> -p <port> -U <username> -W -d <db name>

About

License:MIT License


Languages

Language:Dockerfile 100.0%