@@ -803,17 +803,21 @@ This mount type allows mounting `tmpfs` in the build container.
803
803
804
804
### RUN --mount=type=secret
805
805
806
- This mount type allows the build container to access secure files such as
807
- private keys without baking them into the image.
808
-
809
- | Option | Description |
810
- | ---------- | ------------------------------------------------------------------------------------------------- |
811
- | ` id ` | ID of the secret. Defaults to basename of the target path. |
812
- | ` target ` , ` dst ` , ` destination ` | Mount path. Defaults to ` /run/secrets/ ` + ` id ` . |
813
- | ` required ` | If set to ` true ` , the instruction errors out when the secret is unavailable. Defaults to ` false ` . |
814
- | ` mode ` | File mode for secret file in octal. Default ` 0400 ` . |
815
- | ` uid ` | User ID for secret file. Default ` 0 ` . |
816
- | ` gid ` | Group ID for secret file. Default ` 0 ` . |
806
+ This mount type allows the build container to access secret values, such as
807
+ tokens or private keys, without baking them into the image.
808
+
809
+ By default, the secret is mounted as a file. You can also mount the secret as
810
+ an environment variable by setting the ` env ` option.
811
+
812
+ | Option | Description |
813
+ | ------------------------------ | --------------------------------------------------------------------------------------------------------------- |
814
+ | ` id ` | ID of the secret. Defaults to basename of the target path. |
815
+ | ` target ` , ` dst ` , ` destination ` | Mount the secret to the specified path. Defaults to ` /run/secrets/ ` + ` id ` if unset and if ` env ` is also unset. |
816
+ | ` env ` | Mount the secret to an environment variable instead of a file, or both. (since Dockerfile v1.10.0) |
817
+ | ` required ` | If set to ` true ` , the instruction errors out when the secret is unavailable. Defaults to ` false ` . |
818
+ | ` mode ` | File mode for secret file in octal. Default ` 0400 ` . |
819
+ | ` uid ` | User ID for secret file. Default ` 0 ` . |
820
+ | ` gid ` | Group ID for secret file. Default ` 0 ` . |
817
821
818
822
#### Example: access to S3
819
823
@@ -829,6 +833,25 @@ RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \
829
833
$ docker buildx build --secret id=aws,src=$HOME /.aws/credentials .
830
834
```
831
835
836
+ #### Example: Mount as environment variable
837
+
838
+ The following example takes the secret ` API_KEY ` and mounts it as an
839
+ environment variable with the same name.
840
+
841
+ ``` dockerfile
842
+ # syntax=docker/dockerfile:1
843
+ FROM alpine
844
+ RUN --mount=type=secret,id=API_KEY,env=API_KEY \
845
+ some-command --token-from-env API_KEY
846
+ ```
847
+
848
+ Assuming that the ` API_KEY ` environment variable is set in the build
849
+ environment, you can build this with the following command:
850
+
851
+ ``` console
852
+ $ docker buildx build --secret id=API_KEY .
853
+ ```
854
+
832
855
### RUN --mount=type=ssh
833
856
834
857
This mount type allows the build container to access SSH keys via SSH agents,
0 commit comments