-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mounting secret as environment variable does not behave as expected. #5439
Comments
I double checked, and mounting the secret as an env-var was added in this PR; Which is indeed part of BuildKit 0.16 (default builder in Docker 27.3).
However, I was not able to reproduce your issue test 1# syntax=docker/dockerfile:1
FROM alpine
RUN --mount=type=secret,id=test-secret,env=TESTVAR \
echo "$TESTVAR" > /test.txt \ export test1="testing 123"
docker build --secret id=test-secret,env=test1 --no-cache -t foo .
docker run --rm foo cat /test.txt
testing 123 test 2# syntax=docker/dockerfile:1
FROM alpine
RUN --mount=type=secret,id=test-secret,env=TESTVAR \
echo -e $TESTVAR > /test.txt export test1="testing 234"
docker build --secret id=test-secret,env=test1 --no-cache -t foo .
docker run --rm foo cat /test.txt
testing 234 test 3# syntax=docker/dockerfile:1
FROM alpine
RUN --mount=type=secret,id=test-secret,env=TESTVAR \
echo $TESTVAR > /test.txt \
&& echo foo > /test2.txt \ export test1="testing 345"
docker build --secret id=test-secret,env=test1 --no-cache -t foo .
docker run --rm foo cat /test.txt
testing 345
docker run --rm foo cat /test2.txt
foo test 4# syntax=docker/dockerfile:1
FROM alpine
RUN --mount=type=secret,id=test-secret,env=TESTVAR \
TESTVAR1=$TESTVAR \
&& echo $TESTVAR1 > /test.txt export test1="testing 456"
docker build --secret id=test-secret,env=test1 --no-cache -t foo .
docker run --rm foo cat /test.txt
testing 456 |
Silly question; are you perhaps using export test1="without sudo"
docker build --secret id=test-secret,env=test1 --no-cache -t foo .
docker run --rm foo cat /test.txt
without sudo
export test1="with sudo"
sudo docker build --secret id=test-secret,env=test1 --no-cache -t foo .
docker run --rm foo cat /test.txt
However using sudo -E docker build --secret id=test-secret,env=test1 --no-cache -t foo .
docker run --rm foo cat /test.txt
with sudo |
That's not a silly question at all, but I wasn't using |
Glad to hear it's working now! I thought I'd mention the One thing worth mentioning is that Dockerfile features are implemented in the Dockerfile "front-end" ("parser"). BuildKit ships with a default version of that parser which is compiled in, but will be the version that shipped with the version of Buildkit (or Docker Engine) that's installed. However, the parser can be updated independently of BuildKit. This may help in situations where you run a build in multiple environments, and not all of those may be running "latest"; if you add # syntax=docker/dockerfile:1 |
I run into the same situation, sporadically my secret environment variable is not there. Specifically, I use
Old:
New
Now sometimes |
Building an image with the dockerfile below,
/test.txt
in the image contains the secret as expected.when the secret source is a file. Using environment variable as source does not work (#3787).However, the file becomes empty if the RUN instruction gets modified to any of the following:
The following RUN instruction behaves as expected, resulting in the creation of file
/test2.txt
containing the string "test2".Output of
docker info
Output of
docker buildx inspect
The text was updated successfully, but these errors were encountered: