Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOCKER - Airflow How can i Init my postgres scripts in Airflow DB when i docker compose

I am testing some stuff where I have to init my Postgres DB DDL into airflow Postgres DB when I compose-up it should automatically init for one time as it will be cached afterward as airflow DB works usually. Thanks

like image 531
Mobeen Avatar asked Nov 05 '25 10:11

Mobeen


1 Answers

As requested in the last comment: Adding your own database to the Airflow Docker-compose file:

Put this piece of code as a service somewhere amongst the other services:

  mypostgres:
    image: postgres:13
    environment:
      POSTGRES_USER: mydbuser
      POSTGRES_PASSWORD: securepassword
      POSTGRES_DB: mydb
    volumes:
      - ./database:/var/lib/postgresql/data
      - ./init-database.sh:/docker-entrypoint-initdb.d/init-database.sh
    restart: always
    

Make sure you have a database-directory and a init-database.sh file in the current directory (otherwise the volume mappings fail)

like image 162
BertC Avatar answered Nov 07 '25 11:11

BertC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!