Notes fanzru's shorts
Date 12 / 18 / 2024
E = mc²
∇²Ψ + V(x)Ψ = EΨ
∫f(x)dx
Back to Shorts
dockerpostgresqldatabase

Docker Compose PostgreSQL

2,341 views

Create docker-compose.yml

yaml
version: '3.8'

services:
  postgres:
    image: postgres:15-alpine
    container_name: postgres_db
    restart: always
    environment:
      POSTGRES_USER: myuser
      POSTGRES_PASSWORD: mypassword
      POSTGRES_DB: mydb
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data

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

volumes:
  postgres_data:

Run

bash
docker-compose up -d

Access

  • PostgreSQL: localhost:5432
  • pgAdmin: http://localhost:5050

Connect in pgAdmin

  1. Open pgAdmin at localhost:5050
  2. Add new server:
    • Name: Local Postgres
    • Host: postgres (service name)
    • Port: 5432
    • Username: myuser
    • Password: mypassword

Done! 🚀