Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use docker-entrypoint-initdb.d #1

Open
mohdovais opened this issue Sep 14, 2020 · 1 comment
Open

Use docker-entrypoint-initdb.d #1

mohdovais opened this issue Sep 14, 2020 · 1 comment

Comments

@mohdovais
Copy link

If we create a Dockerfile

FROM postgres:12.4-alpine
ADD /SQL/*.sql /docker-entrypoint-initdb.d/

and then use it in docker-compose-postgres-pgadmin4.yml:

version: '3.5'

services:
  postgres:
    container_name: postgres
    build: .

...
...

then it will automatically run those sql files for data setup.

What do you think?

If you would like to do additional initialization in an image derived from this one, add one or more *.sql, *.sql.gz, or *.sh scripts under /docker-entrypoint-initdb.d (creating the directory if necessary). After the entrypoint calls initdb to create the default postgres user and database, it will run any *.sql files, run any executable *.sh scripts, and source any non-executable *.sh scripts found in that directory to do further initialization before starting the service.

Warning: scripts in /docker-entrypoint-initdb.d are only run if you start the container with a data directory that is empty; any pre-existing database will be left untouched on container startup. One common problem is that if one of your /docker-entrypoint-initdb.d scripts fails (which will cause the entrypoint script to exit) and your orchestrator restarts the container with the already initialized data directory, it will not continue on with your scripts.

@shamimgeek
Copy link
Owner

Yes, It will automatically create db schema or execute scripts.
in this project i have done same thing https://github.com/shamimgeek/url-shortner/blob/master/database/Dockerfile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants