Created
January 11, 2024 21:35
-
-
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.
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
# 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