Skip to content
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

Run a script the first time an image is run. #134

Open
jacobalberty opened this issue Jan 25, 2017 · 3 comments
Open

Run a script the first time an image is run. #134

jacobalberty opened this issue Jan 25, 2017 · 3 comments
Labels

Comments

@jacobalberty
Copy link

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.

@asottile
Copy link
Contributor

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

@jacobalberty
Copy link
Author

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.

@asottile
Copy link
Contributor

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?)

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

No branches or pull requests

2 participants