Make database connection persistant

64 Views Asked by At

I have a superset container running with a postgreSQLdatabase.All is working fine. I can see my table and making queries from superset SQL Lab.

  • I also added dataset, created chart and dashboard.

However when I stop my containers and restart them, I lost all datasets, charts and dashboard. I even lost the database connection I made before (URI method)

Is something wrong with my docker-compose file? How can I avoid this?

version: '3.9'

services:
  superset:
    build:
      context: ./superset
      dockerfile: dockerfile
      extra_hosts:
        - "edge.tdp:141.94.172.122"
    container_name: superset
    environment:
      - ADMIN_USERNAME=admin
      - [email protected]
      - ADMIN_PASSWORD=admin
    ports:
      - '8088:8088'
    volumes:
      - .:/app/tdp
    
  db:
    container_name: postgresql
    image: postgres:15
    restart: unless-stopped
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: postgres
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - ./db-data:/var/lib/postgresql/data
  
1

There are 1 best solutions below

0
On

You also need to pass your database info to the Superset container to use your Postgres instance as backend database.

This should get you going:

  superset:
    environment:
      - ADMIN_USERNAME=admin
      - [email protected]
      - ADMIN_PASSWORD=admin
      - DATABASE_DB=postgres
      - DATABASE_HOST=db
      - DATABASE_PASSWORD=postgres
      - DATABASE_USER=postgres
      - DATABASE_PORT=5432
      - DATABASE_DIALECT=postgresql

This is the relevant config file that reads those environment variables: superset_conig.py

Ultimately, depends on the custom Dockerfile you use which you didn't provide.

Edit: See how Apache Superset build their docker-compose.yml