Run a script the first time an image is run.
Opened this issue · 3 comments
This is a feature request that may be a bit more than dumb-init is intended to contain but it is something I've been looking for in a docker init.
The idea being if there's initial setup (perhaps generating a random password) it should be run when the container is initialized and not when the image is created. It would be nice to have a clean way of performing that task the first time a container is run and then not do it again after.
We've done this in the following way:
CMD ["dumb-init", "./setup.sh"]
#!/usr/bin/env bash
# Run some runtime setup code
echo hi > /etc/app.conf
# exec the application
exec python app.py
This'll allow you to end up with a process tree that looks like
dumb-init
+--- python app.py
and give you your setup code
I mean for a one time run though, runs the first time the container is initialized then never runs again, sort of a post-ininitialization hook. Trying to find a clean way to accomplish it.
Would this be run once per box or once per everything (I don't think the second is possible, and the first you'd need to store some state on disk probably?)