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
2
Answers
Your secret would be mounted as
/run/secrets/mysecret
which can be accessed using thecat
command. TheRUN
command might look something like below:A more complete example below:
--secret
flag using below command:username.txt
secret, which was passed at build time, as the file/app/username.txt
. That can be verified using below command:You can refer this answer for an example of using the mounted secret in a curl command
You can use Docker’s secret management feature to mount a secret file in a Docker image build and use a variable from the secret file in the Dockerfile to authenticate a command. Here are the steps to achieve this:
Note that the
--from=0
option copies the secret file from the build context where the secret was added.This will build the Docker image with the secret file mounted and use the secret value in the command
my_command
using the--auth
flag.