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

Is there a way to add a script which will run always on container start #191

Closed
harrybvp opened this issue Aug 31, 2016 · 8 comments
Closed
Labels
question Usability question, not directly related to an error with the image

Comments

@harrybvp
Copy link

Currently scripts present inside docker-entrypoint-initdb.d/* will run only once (during initialization).

I have a script which does health checkup and I would like that script to be executed always i.e. whenever container starts.

One way could be to modify docker-entrypoint.sh but i was wondering if it's possible w/o modifying entrypoint script.

@yosifkit
Copy link
Member

It is not something we had considered. Is it something that could be accomplished with HEALTHCHECK in your Dockerfile or in your docker run?

@harrybvp
Copy link
Author

harrybvp commented Sep 1, 2016

@yosifkit Thanks for response!
I have a requirement to do more than a health checkup (some business logic) on each container start.
I think it would be great to have that support in docker-entrypoint.sh

However for now , I created an Dockerfile with based image as postgres and added a RUN command to modify docker-entrypoint.sh using sed (inserting my logic somewhere in that entry point script).

@saikatguha
Copy link

I have another scenario which requires running a command each time the container is started. My build system outputs a generated script that adds database roles (if not exists) for currently enabled services. The new roles.sql file in the docker-entrypoint-initdb.d/ triggers a rebuild of the image. That triggers docker-compose to recreate the postgres container. The data directory comes from a persistent volume, however, and due its presence the new init scripts are not run even though they are written to handle existing data.

It would be useful to have the entrypoint trigger scripts for different events. e.g., docker-entrypoint-initdb.d/ for a brand spanking new containers like today, and scripts in docker-entrypoint-on-every-start.d/ every time a container is started.

@tianon
Copy link
Member

tianon commented May 7, 2018

It's a mongo example, but it should be applicable to postgres as well: docker-library/mongo#249 (comment) (basically, start a process in the background that waits for the database to be up and ready before starting the database itself, then make sure it exits cleanly after the desired business logic is performed).

Closing, since we have no intention of explicitly supporting this in the image itself.

@gko
Copy link

gko commented Sep 17, 2023

It's a mongo example, but it should be applicable to postgres as well: docker-library/mongo#249 (comment) (basically, start a process in the background that waits for the database to be up and ready before starting the database itself, then make sure it exits cleanly after the desired business logic is performed).

Closing, since we have no intention of explicitly supporting this in the image itself.

This is not applicable to postgres cause docker-entrypoint.sh runs only if it's not sourced or executed from another file:
https://github.com/docker-library/postgres/blob/master/14/alpine3.18/docker-entrypoint.sh#L349-L351

@yosifkit
Copy link
Member

This is not applicable to postgres cause docker-entrypoint.sh runs only if it's not sourced or executed from another file: https://github.com/docker-library/postgres/blob/master/14/alpine3.18/docker-entrypoint.sh#L349-L351

And this scenario is covered by the example I gave when creating the source-able entrypoint: #496 (comment)

@mpasternak

This comment was marked as off-topic.

@mpasternak
Copy link

I realize this was 8 years, but anybody interested can see this little beauty of mine: how to run autotune script and restart server after the database (and the initial configuration) has been created -- use "docker-ensure-initdb.sh" of course, here's an example: https://github.com/iplweb/bpp/tree/dev/deploy/dbserver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests

7 participants