Skip to content

Instantly share code, notes, and snippets.

@AlecTaylor
Last active August 31, 2018 04:25
Show Gist options
  • Save AlecTaylor/0f38ba61ed866dd5187c06f67e6f8ed4 to your computer and use it in GitHub Desktop.
Save AlecTaylor/0f38ba61ed866dd5187c06f67e6f8ed4 to your computer and use it in GitHub Desktop.
env vars docker ENTRYPOINT
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DOCKER_TAG="${DOCKER_TAG:-scratch0}"
cc="$(which ${CC:-x86_64-linux-musl-gcc})" # Choose any cross compiler, or just `gcc` if you're on a Linux box
cc_flags="${CC_FLAGS:--static}"
"$cc" "$DIR/env.c" -o "$DIR/env" -Wno-implicit-function-declaration "$cc_flags"
docker build --compress --force-rm --tag "$DOCKER_TAG" .
docker run --rm "$DOCKER_TAG" -e FOO=bar
# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# HOSTNAME=eb77d24c5962
# HOME=/
FROM scratch
COPY env /env
ENTRYPOINT ["/env"]
int main(int argc, char **argv, char** envp) { for(char** env=envp;*env!=0;env++) puts(*env, "\n"); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment