Skip to content

Instantly share code, notes, and snippets.

@malcolmgreaves
Created January 11, 2024 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malcolmgreaves/48ed4553a1bb7a67e9c72d07f842d7f1 to your computer and use it in GitHub Desktop.
Save malcolmgreaves/48ed4553a1bb7a67e9c72d07f842d7f1 to your computer and use it in GitHub Desktop.
Example passing a secret value via an env var to a docker build.
# Run this example:
#
# mysecret=SECRET_VALUE docker build --secret id=mysecret,env=mysecret -f Dockerfile -t deleteme .
#
FROM debian:trixie-slim
RUN <<EOF cat >> file
#!/bin/bash
if [[ -z "\${MYSECRET}" ]]; then
echo "No MYSECRET env var!!!"
else
echo "I can use MYSECRET here!"
fi
EOF
RUN chmod +x file
RUN cat file
RUN --mount=type=secret,id=mysecret MYSECRET=$(cat /run/secrets/mysecret) ./file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment