0

I am using a https://hub.docker.com/_/postgres/ (alpine based postgres container) for database setup. I have some a shell script which basically checks the version of software by running a psql query and compares it with the latest version, if there is a difference in version then pulls the latest sql files from github and updates the database. I want this shell script to run whenever the container starts. I tried to keep this script in /docker-entrypoint-initdb.d but later found that the scripts inside /docker-entrypoint-initdb.d do not run if the database is already initialized, so it does not solve my problem. I also tried using entrypoint: /custom-entrypoint-override.sh in my docker-compose file but then this script executes before the postgres is started and so the psql command in my shell script failed, so it also did not solve my problem. If anyone has any solution for this, please let me know. Thanks in advance.

  • In your custom entrypoint script, wrap your code in the `docker_temp_server_start` and `docker_temp_server_stop` functions from the normal docker-entrypoint.sh script https://github.com/docker-library/postgres/blob/master/14/bullseye/docker-entrypoint.sh – Hans Kilian Feb 17 '22 at 11:50
  • You need to run this script from a separate container. What you're describing sounds very similar to a _database migration_ tool – if the application's required database schema has changed, update the database accordingly – and this is usually bundled with the application, and doesn't require restarting the database to apply. [How do you perform Django database migrations when using Docker-Compose?](https://stackoverflow.com/questions/33992867/how-do-you-perform-django-database-migrations-when-using-docker-compose) discusses some approaches for modifying an application image to do this. – David Maze Feb 17 '22 at 11:51

0 Answers0