PostgreSQL with Docker compose



examples/postgresql/Dockerfile
FROM python:3
WORKDIR /opt
RUN pip install psycopg2==2.9.3
# COPY . .

examples/postgresql/docker-compose.yml
version: '3'
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    tty: true
    command: bash
    volumes:
      - .:/opt
    environment:
      POSTGRES_USER: username
      POSTGRES_PASSWORD: password
      POSTGRES_DB: default_database

  pgdatabase:
    image: 'postgres:latest'
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: username
      POSTGRES_PASSWORD: password
      POSTGRES_DB: default_database
    volumes:
      - pg-data-volume:/var/lib/postgresql/data/

volumes:
  pg-data-volume:

docker-compose up


docker exec -it postgresql_app_1 bash