Postgresql client, interactive, or to run a single script or execute file content.
docker run --rm -it --network host \
paolodenti/psqlclient \
psql postgresql://<username>:<password>@<host>:<port>/<db name>
# execute \dt;
docker run --rm --network host \
paolodenti/psqlclient \
psql postgresql://<username>:<password>@<host>:<port>/<db name> \
-c "\dt;"
# 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
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>
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>