Description
Over in postgis/docker-postgis#35, I had a user ask about adding their own script to /docker-entrypoint-initdb.d
via docker-compose
without overwriting the script I use for initializing PostGIS. My suggestion was to bind-mount individual scripts, but it dawned on me that it might be nice to be able to add scripts to subdirectories of /docker-entrypoint-initdb.d
and have them sourced or executed according to the existing logic.
The main drawback I see of making this change is that it's possible that existing users of the postgres
image may already have files in subdirectories of /docker-entrypoint-initdb.d
that they don't want to have executed directly by the postgres
entrypoint. Another minor but solvable issue is maintaining the execution order of the scripts, which I believe I documented when this functionality was originally added:
These initialization files will be executed in sorted name order as defined by the current locale, which defaults to
en_US.utf8
Activity
yosifkit commentedon Jul 26, 2016
I agree about the main drawback; I'd rather not publish a breaking change. The sorting of a
find
should be about the same as globing; we can even make sure that everything within a directory comes before sub-directories. Maybe we hide it behind an environment flag to turn it on? If we were to add it would we limit the depth when finding scripts/sql?Maybe we just recommend users mount a script and have it run other scripts in their folders.
md5 commentedon Jul 26, 2016
@yosifkit I think your second suggestion sounds better than adding another environment variable
md5 commentedon Jul 26, 2016
Also, I thought
find
usesreaddir
orderstepankuzmin commentedon Jun 21, 2018
My solution is mounting
./initdb.d
folder to/initdb.d
and./initdb.sh
script to/docker-entrypoint-initdb.d/initdb.sh
:nullhack commentedon Jul 10, 2019
A simple solution is to create a file (
init.sh
inside/docker-entrypoint-initdb.d/initdb.sh
) with the following content:This will recurse all sub-directories inside
/docker-entrypoint-initdb.d/
and run the files the same way the original Dockerfile doyosifkit commentedon Dec 18, 2019
Closing since this is not something we want to add.
Since initdb scripts can be sourced (#452) and everything in the script is functionalized (#496), a custom script in initdb can easily use the
docker_process_init_files
function to recurse as deeply as desired.Related issues #179, #605, docker-library/mysql#192, docker-library/mysql#193
2 remaining items