-
Notifications
You must be signed in to change notification settings - Fork 470
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
Proposal: Support multiple database #175
Comments
imho: we need some risk assessment, because the upstream image ( |
Ok, how long can it take and are there any alternatives? I re-read several related issues on this topic, and most of them are already closed. It all comes down to the fact that the container user must independently override the initialization script. So why not extend this method here, since it image is not a direct Postgres provider? |
I agree with @ImreSamu, risk assessment is necessary to make sure compatibility can be maintained with the postgres images. While it's not been explicitly stated/documented anywhere that I know of, the postgis images can ideally be used as drop-in replacements for the postgres images. The postgres images can be considered "upstream" and the changes that go into the postgis images need to be analyzed to make sure this compatibility isn't broken. And as much as possible, the extension facilities and recommended usage patterns prescribed by the upstream image should be used and continue to work with the postgis images. In this specific case, I don't see how the implementation @HELSIS666 lays out would break compatibility, but it doesn't exactly follow the upstream recommendations. The reference that @ImreSamu linked to does begin to spell out ways of accomplishing the same thing. Given all of this, I actually have a slightly different proposal: Maybe creating multiple databases within a single container should be done by a separate script which reads different environment variables and provides a solution that is decoupled from what is inherited from the postgres images? Maybe a script that reads different environment variables such as |
In light of apparent agreement of my most recent comment... @HELSIS666 would you like to contribute a PR that would implement a separate script which we can include in the image and provide functionality to initialize multiple databases based on separate optional environment variables? Alternatively, we can continue discussion here about the specifics of an approach or implementation, and only start working toward a PR once we feel we have a better understanding and more consensus on how to move forward. If it's the case that nobody has free time or desire to work on the issue and just use the prescribed image customization patterns documented in the upstream image, we can close out this issue. |
@phillipross I would recommend a slightly different approach
With that approach, anyone can add additional init scripts of their own in a derived image that call "the other script" based on whatever environment variables they choose. This can either be done in an image derived Edit: I guess the missing part is that the base image is actually creating the database for the core DB. I feel like that part is easy enough to include in "the other script" above. Either that or ask the |
We did a lot of refactoring and "functionalizing" in docker-library/postgres#496; combine that with docker-library/postgres#452 and it should be possible to call any function you want from the orginial entrypoint. The functions not beginning with an underscore are considered the "public" interface of the script when sourcing it (and from sourced initdb.d scripts) and so will be kept as a stable as possible (functionality, names, and arguments will be very unlikely to change). On the flip side, functions beginning with an underscore are "private" and can change at any time. So something like this should work (in a non-executable sh file): #!/bin/bash
docker_process_sql --dbname postgres --set db="$myVariable" <<-'EOSQL'
CREATE DATABASE :"db" ;
EOSQL I would have said to just use TL;DR: I'd recommend just creating any extra databases via sql. Side note: |
Yes, I think it’s worth more to analyze all the possible solutions, since I forgot that the databases have their own settings, roles, etc. Would be nice to have an optional interface that will wait for a list of databases settings. Mounting a custom initialization script and settings file should solve my problems, but I would like to hear all the comments on this |
I think this task should really be moved to the upstream postgres repo and discussed there. While possibly a good idea, I think it should be the PG parent that makes this possible, whereas postgis image should be as simple as possible, and just add various versions of postgis (and related) extensions. |
Description:
Add support for creating multiple databases when starting a container. This would be convenient for docker-compose. Implementation in other container.
Example:
/docker-compose.yaml
Solutions:
Replace the variable POSTGRES_DB with the expression
$(echo $POSTGRES_DB | tr ',' ' ')
. This should give us the desired result:/initdb-postgis.sh
The text was updated successfully, but these errors were encountered: