Add `--file` flag for `docker secret create` command

This fix tries to address the issue raised in 28581 and 28927
where it is not possible to create a secret from a file (only
through STDIN).

This fix add a flag `--file` to `docker secret create` so that
it is possible to create a secret from a file with:
```
docker secret create --file secret.in secret.name
```

or
```
echo TEST | docker secret create --file - secret.name
```

Related docs has been updated.

An integration test has been added to cover the changes.

This fix fixes 28581.
This fix is related to 28927.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang 2016-11-19 17:41:11 -08:00 committed by Tibor Vass
parent fd0957a407
commit c8f99f00d2
1 changed files with 20 additions and 7 deletions

View File

@ -18,13 +18,15 @@ keywords: ["secret, create"]
```Markdown ```Markdown
Usage: docker secret create [OPTIONS] SECRET Usage: docker secret create [OPTIONS] SECRET
Create a secret using stdin as content Create a secret from a file or STDIN as content
Options: Options:
-f, --file string Read from a file or STDIN ('-')
--help Print usage --help Print usage
-l, --label list Secret labels (default []) -l, --label list Secret labels (default [])
``` ```
Creates a secret using standard input for the secret content. You must run this Creates a secret using standard input or from a file for the secret content. You must run this
command on a manager node. command on a manager node.
## Examples ## Examples
@ -32,7 +34,18 @@ command on a manager node.
### Create a secret ### Create a secret
```bash ```bash
$ cat secret.json | docker secret create secret.json $ cat secret.json | docker secret create -f - secret.json
mhv17xfe3gh6xc4rij5orpfds
$ docker secret ls
ID NAME CREATED UPDATED SIZE
mhv17xfe3gh6xc4rij5orpfds secret.json 2016-10-27 23:25:43.909181089 +0000 UTC 2016-10-27 23:25:43.909181089 +0000 UTC 1679
```
### Create a secret with a file
```bash
$ docker secret create --file secret.in secret.json
mhv17xfe3gh6xc4rij5orpfds mhv17xfe3gh6xc4rij5orpfds
$ docker secret ls $ docker secret ls
@ -43,7 +56,7 @@ mhv17xfe3gh6xc4rij5orpfds secret.json 2016-10-27 23:25:43.90918108
### Create a secret with labels ### Create a secret with labels
```bash ```bash
$ cat secret.json | docker secret create secret.json --label env=dev --label rev=20161102 $ cat secret.json | docker secret create secret.json -f - --label env=dev --label rev=20161102
jtn7g6aukl5ky7nr9gvwafoxh jtn7g6aukl5ky7nr9gvwafoxh
$ docker secret inspect secret.json $ docker secret inspect secret.json