Skip to content

Commit 9a9029b

Browse files
authored
Merge pull request moby#5296 from dvdksn/docs-runmount-secret-env
docs: run mount secret env dockerfile example
2 parents 54e43bb + 85b0933 commit 9a9029b

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

frontend/dockerfile/docs/reference.md

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -803,17 +803,21 @@ This mount type allows mounting `tmpfs` in the build container.
803803

804804
### RUN --mount=type=secret
805805

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`. |
817821

818822
#### Example: access to S3
819823

@@ -829,6 +833,25 @@ RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \
829833
$ docker buildx build --secret id=aws,src=$HOME/.aws/credentials .
830834
```
831835

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+
832855
### RUN --mount=type=ssh
833856

834857
This mount type allows the build container to access SSH keys via SSH agents,

0 commit comments

Comments
 (0)