Can someone please provide an example of the following command:
DOCKER_BUILDKIT=1 docker build --secret:id=mysecret,src=/local/secret ...
I don't know how to access the variables from secret file after mounting.
For example: I want to set Proxy using the secret passed and run an install command
Your secret would be mounted as /run/secrets/mysecret
which can be accessed using the cat
command. The RUN
command might look something like below:
RUN --mount=type=secret,id=mysecret \
cat /run/secrets/mysecret
A more complete example below:
FROM node:16
WORKDIR /app
RUN --mount=type=secret,id=USERNAME \
cat /run/secrets/USERNAME > /app/username.txt
--secret
flag using below command:DOCKER_BUILDKIT=1 docker build --secret id=USERNAME,src=username.txt -t node:16-secret .
username.txt
secret, which was passed at build time, as the file /app/username.txt
. That can be verified using below command:docker run --rm -it node:16-secret cat username.txt
You can refer this answer for an example of using the mounted secret in a curl command