0

So I created an application that runs in docker containers. For this I also have a postgresql container as database and with every version I expand this database. For this I have new sql files that need to run to create the tables. Only when I try todo this in my docker compose file it never picks up the new scripts. This is my script :

FROM postgres:11.5-alpine

EXPOSE 5432
ENV POSTGRES_USER test
ENV POSTGRES_PASSWORD test
ENV POSTGRES_DB tm
ADD CreateDB.sql /docker-entrypoint-initdb.d/
ADD version200.sql /docker-entrypoint-initdb.d/
ADD version210.sql /docker-entrypoint-initdb.d/
ADD version3.sql /docker-entrypoint-initdb.d/

The last file version3.sql is the newest but this isn't added to the database it won't execute. Do I need todo this in a different way? Or should I just go into the postgresql container? To start the application I use this script:

version: '3.3'
services:

  app-db:
    build: ./db
    ports:
      - '5432:5432'
    volumes:
      - ./data:/var/lib/postgresql/data

  app-web:
    build: ./web
    ports:
      - "8080:8080"
2
  • Scripts in /docker-entrypoint-initdb.d only run the very first time you create the database. If the database already exists (if there are files in the storage you mount into the database container) then the scripts won't be (re-)run. You probably want to use your application framework's database migration system instead, which is more designed for making incremental schema changes and isn't tied to Docker. Commented Sep 14, 2022 at 13:09
  • ...for example, also see docker-compose mysql init sql is not executed, which suggests deleting all of the database data to get the init scripts to run (with obvious consequences). Commented Sep 14, 2022 at 13:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.