← All Articles A Product of Kinsa Creative

PostgreSQL and pgAdmin in a Docker Container

A Docker container running pgAdmin with PostgreSQL.

Create a docker-compose.yml file:

version: '3.8'

services:
  postgres:
    image: postgres:16
    container_name: postgres_db
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: admin123
      POSTGRES_DB: mydb
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data

  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin_gui
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: admin123
    ports:
      - "5050:80"
    depends_on:
      - postgres

volumes:
  postgres_data:

To start:

docker-compose up -d

Then open your browser to http://localhost:5050 and log in with the following email and password (as defined in the docker-compose.yml file):

The first time launching, add a new server in pgAdmin:


To stop and remove the containers (preserving the data in the volume):

docker-compose down

To remove the database:

docker-compose down -v

To just stop (to restart later):

docker-compose stop


To copy a SQL file into the container:

docker cp /path/to/your/dump.sql postgres_db:/tmp/dump.sql

To then load it:

docker exec -i postgres_db psql -U admin -d mydb -f /tmp/dump.sql

Feedback?

Email us at enquiries@kinsa.cc.