Automatically run cli script during/after docker startup

Options
jfg1306
jfg1306 Member Posts: 14 ✭✭

Hello,

is there a place or option somewhere that allows us to automatically run CLI scripts right after the startup completed ?

The idea comes from PostgreSQL where you can create .sql files and place them in a specific path (here initdb.d) and they will get automatically executed.

[...]

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.

[...] (postgres - Official Image | Docker Hub)

We are aware that we can execute the CLI scripts either manually inside the instance or from the outside through docker exec.

Greetings,

Filip.

Best Answer

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 923 admin
    #2 Answer ✓
    Options

    Hi @jfg1306,

    There is currently not a way to automatically run CLI scripts, but I always thought it would be a cool feature so if you feel strongly about it please request it via support ;)

    As it stands, two common options for configuration are triggering the scripts as you have noted, or using SEMP to perform your configuration. Either way I'd recommend a SEMP call before executing either to check that the container is up and running :)

Answers

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 923 admin
    #3 Answer ✓
    Options

    Hi @jfg1306,

    There is currently not a way to automatically run CLI scripts, but I always thought it would be a cool feature so if you feel strongly about it please request it via support ;)

    As it stands, two common options for configuration are triggering the scripts as you have noted, or using SEMP to perform your configuration. Either way I'd recommend a SEMP call before executing either to check that the container is up and running :)