Skip to content

Add option to let the container stop gracefully after docker-entrypoint-initdb.d #424

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

Closed
metas-ts opened this issue Mar 24, 2018 · 8 comments
Labels
Request Request for image modification or feature

Comments

@metas-ts
Copy link

metas-ts commented Mar 24, 2018

Hi,
I have two usage scenarios where imho it would make a lot of sense to have the option to just init a postgres DBMS via scripts in /docker-entrypoint-initdb.d and then have the docker container exit gracefully as soon as those init scripts are run.

This would support my following use cases:

  • on my jenkins, I would like to get an initial pg-dump, then apply some migration scripts and then create and publish a new pg-dump. As soon as that's done, the docker container should stop.
  • in my kubernetes cluster, I would like to use a postgres docker container as a kubernetes init-container to prepare the grounds before the real postgresql container actually starts. Why: the init-container's image contains a lot of stuff that is only needed for database inititalization (in my case curl and a java runtime environment...yeah, better don't ask ;-) )..but it writes the database files into a volume which is then used by the real production postgres container.

wdyt?

@wglambert wglambert added the Request Request for image modification or feature label Apr 25, 2018
@eric-cancil
Copy link

+1 - this would be super useful for seeding data into a container and then recommitting it (think allowing developers to pull a container with seeded data already inside it

@GiannisSialmas
Copy link

GiannisSialmas commented Dec 9, 2018

The last line of the docker-entrypoint.sh seems to be responsible for starting the database.That is

exec "$@"

As a hacky way to accomplish not starting the database, i currently remove the last line of docker-entrypoint.sh using a RUN command with sed inside the Dockerfile like this:

RUN sed -i '$ d' /usr/local/bin/docker-entrypoint.sh

As a more permanent solution, an ENV variable (e.g $DONT_START_DATABASE) and a change to the last lines of the docker-entrypoint.sh to exit the script succesfully before starting the database would be great. Example:

if [ "$DONT_START_DATABASE" = true ]; then
	exit 0;
fi
exec "$@"

As a plus, other people using the hacky solution with sed wouldn't be affected by the change.
What do you think?

@gsf
Copy link

gsf commented Jan 2, 2019

I have a similar kubernetes situation with the following in an init container:

- name: setup
  image: postgres
  args:
  # Trick entrypoint into exiting after setup
  - postgres
  - --version

@tianon
Copy link
Member

tianon commented Jan 25, 2019

I think the --version or sed-based solution (#424 (comment)) is the best we can offer right now, but #496 should make this process completely customizable (which should make this a lot easier to accomplish).

@tianon
Copy link
Member

tianon commented Apr 20, 2020

This is now possible to accomplish properly/cleanly via #496. 🎉 👍

@tianon tianon closed this as completed Apr 20, 2020
@Akkarine
Copy link

Akkarine commented Oct 20, 2020

I have a similar kubernetes situation with the following in an init container:

- name: setup
  image: postgres
  args:
  # Trick entrypoint into exiting after setup
  - postgres
  - --version

Looks like trick does not work anymore

@luckydonald
Copy link

@tianon It's a bit unclear now, how exactly can this be done with the landed #496?

@tianon
Copy link
Member

tianon commented Nov 20, 2024

We added an explicit example in #1150, which happens to solve this specific use case.

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

No branches or pull requests

8 participants