2016-10-27 20:30:32 -04:00
|
|
|
# secret create
|
|
|
|
|
2023-01-06 13:04:05 -05:00
|
|
|
<!---MARKER_GEN_START-->
|
2016-11-19 20:41:11 -05:00
|
|
|
Create a secret from a file or STDIN as content
|
2016-10-27 20:30:32 -04:00
|
|
|
|
2023-01-06 13:04:05 -05:00
|
|
|
### Options
|
|
|
|
|
|
|
|
| Name | Type | Default | Description |
|
|
|
|
|:------------------------------------|:---------|:--------|:----------------|
|
|
|
|
| `-d`, `--driver` | `string` | | Secret driver |
|
|
|
|
| [`-l`](#label), [`--label`](#label) | `list` | | Secret labels |
|
|
|
|
| `--template-driver` | `string` | | Template driver |
|
|
|
|
|
|
|
|
|
|
|
|
<!---MARKER_GEN_END-->
|
2016-10-27 20:30:32 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Description
|
|
|
|
|
2018-12-23 06:27:52 -05:00
|
|
|
Creates a secret using standard input or from a file for the secret content.
|
2017-03-17 02:51:48 -04:00
|
|
|
|
|
|
|
For detailed information about using secrets, refer to [manage sensitive data with Docker secrets](https://docs.docker.com/engine/swarm/secrets/).
|
2016-10-27 20:30:32 -04:00
|
|
|
|
2024-08-16 05:02:10 -04:00
|
|
|
> [!NOTE]
|
2020-04-19 11:08:37 -04:00
|
|
|
> This is a cluster management command, and must be executed on a swarm
|
|
|
|
> manager node. To learn about managers and workers, refer to the
|
|
|
|
> [Swarm mode section](https://docs.docker.com/engine/swarm/) in the
|
|
|
|
> documentation.
|
2018-12-23 06:27:52 -05:00
|
|
|
|
2016-10-27 20:30:32 -04:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
### Create a secret
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
|
|
|
$ printf "my super secret password" | docker secret create my_secret -
|
2017-03-24 04:34:03 -04:00
|
|
|
|
|
|
|
onakdyv307se2tl7nl20anokv
|
2016-11-19 20:41:11 -05:00
|
|
|
|
|
|
|
$ docker secret ls
|
2017-03-24 04:34:03 -04:00
|
|
|
|
|
|
|
ID NAME CREATED UPDATED
|
|
|
|
onakdyv307se2tl7nl20anokv my_secret 6 seconds ago 6 seconds ago
|
2016-11-19 20:41:11 -05:00
|
|
|
```
|
|
|
|
|
|
|
|
### Create a secret with a file
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2017-01-06 15:06:02 -05:00
|
|
|
$ docker secret create my_secret ./secret.json
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2017-03-24 04:34:03 -04:00
|
|
|
dg426haahpi5ezmkkj5kyl3sn
|
2016-10-27 20:30:32 -04:00
|
|
|
|
|
|
|
$ docker secret ls
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2017-03-24 04:34:03 -04:00
|
|
|
ID NAME CREATED UPDATED
|
|
|
|
dg426haahpi5ezmkkj5kyl3sn my_secret 7 seconds ago 7 seconds ago
|
2016-10-27 20:30:32 -04:00
|
|
|
```
|
|
|
|
|
2023-01-06 13:28:29 -05:00
|
|
|
### <a name="label"></a> Create a secret with labels (--label)
|
2016-11-03 17:01:54 -04:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
|
|
|
$ docker secret create \
|
|
|
|
--label env=dev \
|
|
|
|
--label rev=20170324 \
|
|
|
|
my_secret ./secret.json
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2017-03-24 04:34:03 -04:00
|
|
|
eo7jnzguqgtpdah3cm5srfb97
|
2017-02-07 18:42:48 -05:00
|
|
|
```
|
2016-11-03 17:01:54 -04:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2017-01-04 02:13:31 -05:00
|
|
|
$ docker secret inspect my_secret
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2016-11-03 17:01:54 -04:00
|
|
|
[
|
|
|
|
{
|
2017-03-24 04:34:03 -04:00
|
|
|
"ID": "eo7jnzguqgtpdah3cm5srfb97",
|
2016-11-03 17:01:54 -04:00
|
|
|
"Version": {
|
2017-03-24 04:34:03 -04:00
|
|
|
"Index": 17
|
2016-11-03 17:01:54 -04:00
|
|
|
},
|
2017-03-24 04:34:03 -04:00
|
|
|
"CreatedAt": "2017-03-24T08:15:09.735271783Z",
|
|
|
|
"UpdatedAt": "2017-03-24T08:15:09.735271783Z",
|
2016-11-03 17:01:54 -04:00
|
|
|
"Spec": {
|
2017-01-04 02:13:31 -05:00
|
|
|
"Name": "my_secret",
|
2016-11-03 17:01:54 -04:00
|
|
|
"Labels": {
|
|
|
|
"env": "dev",
|
2017-03-24 04:34:03 -04:00
|
|
|
"rev": "20170324"
|
|
|
|
}
|
|
|
|
}
|
2016-11-03 17:01:54 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Related commands
|
2016-10-27 20:30:32 -04:00
|
|
|
|
|
|
|
* [secret inspect](secret_inspect.md)
|
|
|
|
* [secret ls](secret_ls.md)
|
|
|
|
* [secret rm](secret_rm.md)
|