A persistent challenge in creating containers has been how to simply and easily add environment variables or source scripts as a part of various user shells (bash, zsh) and firing things on container startup - particularly if the thing that is starting requires root access.
Today we've dealt with this by:
userEnvProbe
to loginInteractiveShell
to ensure any tool gets these variablesThere are several challenges here.
overrideCommand
to be set to false which has similar challenges - though the label metadata proposal could help here ( Dev container metadata in image labels #18).Rather than all of this, we can have a well defined pattern when features are used. There could even be a simple feature that does nothing more than set up execution of this pattern. Instead of everything described above, we can introduce two well known folder locations:
A profile.d
folder (or a similar name). If a feature places a script in this location, it will be sourced by /etc/bash.bashrc, /etc/zsh/zshrc, /etc/profile.d, and /etc/zsh/zprofile. A single bootstrapper can then be sourced to ensure these scripts are executed with code similar to what you'd find in /etc/profile. However, it would check to see if the bootstrapper has already run to ensure it doesn't fire more than once like in the case of a login interactive shell.
if [ -z "${DEV_CONTAINER_PROFILE_BOOSTRAP_DONE}" ] && [ -d "/usr/local/etc/dev-containers/profile.d" ]; then for script in /usr/local/etc/dev-containers/profile.d/*; do if [ -r "$script" ]; then . $script fi unset script done export DEV_CONTAINER_PROFILE_BOOSTRAP_DONE="true" fi
An entrypoint.d
folder where you can place a scripts that will automatically be executed as a part of the container startup. This eliminates the need for an explicit entrypoint property in devcontainer-features.json
. However, execution is a bit different than profile.d
. It should:
/etc/profile.d
, you can add numeric prefixes to indicate when it should happen.exec
for any arguments passed into it so that the PID for the processor is replaced by the existing entrypoint commands.Features then follow a pattern of placing contents in these folders rather than attempting to manually update configuration.
AlternativesPart of the reason for entrypoint.d
is that most containers do not have systemd or another init system that supports process startup. (The tiny init system that the --init argument adds does not manage process startup). The challenge is systemd is heavy and requires more permissions to the host than is ideal. So while it is an option, its not something we could count on. An alternative would be to use something like supervisord. However, if the desire is just to fire something once at startup rather than keep a process running, its overkill as well. We can also easily document how to wire in supervisord using entrypoint.d
if not provide a dev container feature for it.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4