Last active
March 28, 2024 02:10
-
-
Save joariasl/ed88c2dc556695064dff7d6e89975415 to your computer and use it in GitHub Desktop.
Docker EntryPoint to load environment variables from files to use with file mounted secrets like Secret Store CSI Driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
ENV_PATH_SEPARATOR=${ENV_PATH_SEPARATOR:-':'} | |
oldIFS=$IFS | |
IFS=$ENV_PATH_SEPARATOR | |
for ENV_FILE in $ENV_PATH; do | |
if [ -f "$ENV_FILE" ]; then | |
export $(grep -v '^#' "$ENV_FILE" | xargs -0) | |
else | |
echo "$ENV_FILE is not a file" >&2 | |
fi | |
done | |
IFS=$oldIFS | |
if [ "$IGNORE_EXEC" != "true" ]; then | |
# Running params (or CMD) becomes the container’s PID 1 | |
exec "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a useful Docker EntryPoint to load environment variables from files to use with file mounted secrets like Secret Store CSI Driver
## Params envs
Usage in Dockerfile
or
## Example of env file
envs.env
Dockerfile example
Run container with ENVs
Two or more files
See PID environments inside container
Try it in Kubernetes
secret-provider-class.yaml
configmap.yaml
pod.yaml