@@ -16,16 +16,14 @@ secret mounts or SSH mounts, which expose secrets to your builds securely.
1616
1717## Secret mounts
1818
19- Secret mounts expose secrets to the build containers as files. You [ mount the
20- secrets to the ` RUN `
21- instructions] ( /reference/dockerfile.md#run---mounttypesecret ) that
19+ Secret mounts expose secrets to the build containers, as files or environment
20+ variables. You can use secret mounts to pass sensitive information to your
21+ builds, such as API tokens, passwords, or SSH keys. You [ mount the secrets to
22+ the ` RUN ` instructions] ( /reference/dockerfile.md#run---mounttypesecret ) that
2223need to access them, similar to how you would define a bind mount or cache
2324mount.
2425
25- ``` dockerfile
26- RUN --mount=type=secret,id=mytoken \
27- TOKEN=$(cat /run/secrets/mytoken) ...
28- ```
26+ ### Passing secrets
2927
3028To pass a secret to a build, use the [ ` docker build --secret `
3129flag] ( /reference/cli/docker/buildx/build.md#secret ) , or the
@@ -82,21 +80,40 @@ $ docker build --secret id=API_TOKEN .
8280
8381### Target
8482
85- By default, secrets are mounted to ` /run/secrets/<id> ` . You can customize the
86- mount point in the build container using the ` target ` option in the Dockerfile.
83+ By default, secrets are mounted as files located at ` /run/secrets/<id> ` . You
84+ can customize how the secrets get mounted in the build container using the
85+ ` target ` and ` env ` options for the ` RUN --mount ` flag in the Dockerfile.
8786
88- The following example mounts the secret to a ` /root/.aws/credentials ` file in
89- the build container.
87+ The following example takes secret id ` aws ` and mounts it to ` /run/secrets/aws `
88+ in the build container.
9089
91- ``` console
92- $ docker build --secret id=aws,src=/root/.aws/credentials .
90+ ``` dockerfile
91+ RUN --mount=type=secret,id=aws \
92+ AWS_SHARED_CREDENTIALS_FILE=/run/secrets/aws \
93+ aws s3 cp ...
9394```
9495
96+ To mount a secret as a file with a different name, use the ` target ` option in
97+ the ` --mount ` flag.
98+
9599``` dockerfile
96100RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \
97101 aws s3 cp ...
98102```
99103
104+ To mount a secret as an environment variable instead of a file, use the
105+ ` env ` option in the ` --mount ` flag.
106+
107+ ``` dockerfile
108+ RUN --mount=type=secret,id=aws-key-id,env=AWS_ACCESS_KEY_ID \
109+ --mount=type=secret,id=aws-secret-key,env=AWS_SECRET_ACCESS_KEY \
110+ --mount=type=secret,id=aws-session-token,env=AWS_SESSION_TOKEN \
111+ aws s3 cp ...
112+ ```
113+
114+ It's possible to use the ` target ` and ` env ` options together to mount a secret
115+ as both a file and an environment variable.
116+
100117## SSH mounts
101118
102119If the credential you want to use in your build is an SSH agent socket or key,
0 commit comments