Sign inSign up

gmarrot/postgresql-client

By gmarrot

•Updated 4 months ago

An Alpine image containing PostgreSQL client

Image
Developer tools
0

4.3K

gmarrot/postgresql-client repository overview

⁠PostgreSQL Client Images

Lightweight Docker images containing the PostgreSQL client (psql), based on Alpine Linux. Available in two variants: client only or client + Nginx.

⁠Available Variants

⁠Client Image (PostgreSQL client only)

Minimal image with only the PostgreSQL client for running psql, pg_dump, etc.

TagPostgreSQLAlpineDescription
15153.22PostgreSQL 15
16163.23PostgreSQL 16
17173.23PostgreSQL 17
18183.23PostgreSQL 18
⁠Nginx Image (PostgreSQL client + Nginx)

Image combining Nginx with the PostgreSQL client, suitable for scenarios where both Nginx and PostgreSQL tools are needed in the same container (reverse proxy, API gateways, etc.).

TagPostgreSQLNginxAlpine
15-nginx151.283.22
16-nginx161.283.23
17-nginx171.283.23
18-nginx181.283.23

⁠Supported Platforms

  • linux/amd64
  • linux/arm64

⁠Usage

⁠Run an interactive shell with the PostgreSQL client
docker run -it --rm gmarrot/postgresql-client:18 /bin/ash
# Then inside the container:
psql -h <host> -U <user> -d <database>
⁠Run a psql command directly
docker run --rm gmarrot/postgresql-client:18 psql -h postgres.example.com -U myuser -d mydb -c "SELECT version();"
⁠pg_dump from a remote database
docker run --rm gmarrot/postgresql-client:18 pg_dump -h postgres.example.com -U myuser -d mydb > backup.sql
⁠Nginx image (main process: Nginx)
docker run -d --name nginx-pg gmarrot/postgresql-client:18-nginx
# Nginx runs in the foreground. The psql client is available inside the container if you exec into it.

⁠Docker with Environment Variables

You can pass connection parameters to the container using PostgreSQL's environment variables, which allows psql and other client tools to connect without specifying -h, -U, -d on the command line.

⁠Using -e flags
docker run -it --rm \
  -e PGHOST=postgres.example.com \
  -e PGPORT=5432 \
  -e PGDATABASE=mydb \
  -e PGUSER=myuser \
  -e PGPASSWORD=mypassword \
  gmarrot/postgresql-client:18 psql -c "SELECT version();"
⁠Using an env file
# .env file
PGHOST=postgres.example.com
PGPORT=5432
PGDATABASE=mydb
PGUSER=myuser
PGPASSWORD=mypassword

# Run with --env-file
docker run -it --rm --env-file .env gmarrot/postgresql-client:18 psql
⁠Connecting to a PostgreSQL container on the same Docker network
docker run -it --rm \
  --network my-app-network \
  -e PGHOST=postgres \
  -e PGDATABASE=appdb \
  -e PGUSER=appuser \
  -e PGPASSWORD=secret \
  gmarrot/postgresql-client:18 psql
⁠Supported PostgreSQL Environment Variables
VariableDescription
PGHOSTDatabase server hostname
PGHOSTADDRIP address of the server (avoids DNS lookup)
PGPORTPort number (default: 5432)
PGDATABASEDatabase name
PGUSERPostgreSQL username
PGPASSWORDPassword (not recommended for security; prefer PGPASSFILE or secrets)
PGPASSFILEPath to .pgpass password file
PGSSLMODESSL mode: disable, allow, prefer, require, verify-ca, verify-full
PGCONNECT_TIMEOUTConnection timeout in seconds
PGCLIENTENCODINGClient character encoding (e.g. UTF8)
PGAPPNAMEApplication name shown in pg_stat_activity
PGOPTIONSAdditional connection options
PGSERVICEService name from ~/.pg_service.conf

For a complete list, see the PostgreSQL libpq environment variables documentation⁠.

⁠Base Images

  • Client: dhi.io/alpine-base
  • Nginx: dhi.io/nginx

⁠License

MIT License. See LICENSE⁠ for details.

Tag summary

Content type

Image

Digest

sha256:4e54aa040…

Size

6.7 MB

Last updated

4 months ago

docker pull gmarrot/postgresql-client:15-nginx