Skip to content
Search

PgAdmin

lastmod 2025-02-14created 2020-09-1614 edits

pgAdmin is the most popular and feature rich Open Source administration and development platform for PostgreSQL, the most advanced Open Source database in the world.

Categories

Simple running

$ docker run -p 5050:80 -e "[email protected]" -e "PGADMIN_DEFAULT_PASSWORD=a12345678" -d  dpage/pgadmin4

docker-compose example

version: '3.3'

services:
  dbPostgres:
    image: postgres:10
    restart: always
#    volumes:
#      - $DATABASE:/var/lib/postgresql/data
    ports:
      - 5433:5432
    environment:
      POSTGRES_USER: username
      POSTGRES_PASSWORD: 6090

  pgadmin:
    image: dpage/pgadmin4
    restart: always
    depends_on:
      - dbPostgres
#    volumes:
#      - $BACKUP:/var/lib/pgadmin
    ports:
      - 9090:80
    environment:
      - "[email protected]"
      - "PGADMIN_DEFAULT_PASSWORD=0000"

Provisioning connections docker-compose example

A way to store connection information for a Postgresql server, implemented with docker-compose. You need to create a Password File and a servers.json file.

version: '3.8'

services:
  postgres:
    container_name: answer-pg
    image: postgres:13
    restart: always
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - 5432:5432
    environment:
      - TZ=Asia/Seoul
      - POSTGRES_USER=${POSTGRES_USER:-recc}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-recc1234}
    networks:
      - postgres_net

  pgadmin:
    container_name: answer-pgadmin
    image: dpage/pgadmin4:latest
    restart: always
    depends_on:
      - postgres
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    ports:
      - 9090:80
    environment:
      - TZ=Asia/Seoul
      - PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL:-recc@localhost}
      - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD:-recc1234}
      - PGADMIN_SERVER_JSON_FILE=/tmp/servers.json
    networks:
      - postgres_net
    entrypoint:
      - sh
      - -c
      - |
        mkdir -p /var/lib/pgadmin/storage/recc_localhost &&
        cat << EOF > /var/lib/pgadmin/storage/recc_localhost/pgpassfile &&
        answer-pg:5432:*:${POSTGRES_USER:-recc}:${POSTGRES_PASSWORD:-recc1234}
        EOF
        chmod 600 /var/lib/pgadmin/storage/recc_localhost/pgpassfile &&
        cat << EOF > /tmp/servers.json &&
        {
            "Servers": {
                "1": {
                    "Name": "answer-postgres",
                    "Group": "Servers",
                    "Host": "answer-pg",
                    "Port": 5432,
                    "MaintenanceDB": "postgres",
                    "Username": "${POSTGRES_USER:-recc}",
                    "PassFile": "/pgpassfile",
                    "SSLMode": "prefer",
                    "SSLCert": "<STORAGE_DIR>/.postgresql/postgresql.crt",
                    "SSLKey": "<STORAGE_DIR>/.postgresql/postgresql.key",
                    "SSLCompression": 0,
                    "Timeout": 10,
                    "UseSSHTunnel": 0,
                    "TunnelPort": "22",
                    "TunnelAuthentication": 0
                }
            }
        }
        EOF
        /entrypoint.sh

volumes:
  postgres_data:
  pgadmin_data:

networks:
  postgres_net:

The servers.json file can be exported with the following command.

## docker container 내부 기준, 사용 방법:
cd /pgadmin4
python setup.py --dump-servers /tmp/servers.json --user recc@localhost

The pgpassfile file must be written in the following format.

hostname:port:database:username:password

Environment Variables

PGADMIN_DEFAULT_EMAIL
This is the email address used when setting up the initial administrator account to login to pgAdmin. This variable is required and must be set at launch time.
PGADMIN_DEFAULT_PASSWORD
This is the password used when setting up the initial administrator account to login to pgAdmin. This variable is required and must be set at launch time.

Troubleshooting

Default email/password error in Dockerfile

Even if you configure the Dockerfile, the initial EMAIL and password may not work properly:

version: '3.3'
services:
  pgadmin:
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: 0000

Don't do it as above; change the environment contents as below instead.

version: '3.3'
services:
  pgadmin:
    image: dpage/pgadmin4
    environment:
      - "[email protected]"
      - "PGADMIN_DEFAULT_PASSWORD=0000"

no password supplied

The following error may be printed when connecting to the database.

fe_sendauth: no password supplied

Keep the following options on the first connection.

"SSLMode": "prefer",
"SSLCert": "<STORAGE_DIR>/.postgresql/postgresql.crt",
"SSLKey": "<STORAGE_DIR>/.postgresql/postgresql.key",
"SSLCompression": 0,

See also

Favorite site

author Zer0 sitemap