Skip to content

Commit 846d413

Browse files
authored
Merge pull request #512 from docker/feat/docs
feat(pass): documentation
2 parents 624377a + 9bc3f22 commit 846d413

3 files changed

Lines changed: 72 additions & 7 deletions

File tree

plugins/pass/command.go

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package pass
1717
import (
1818
"context"
1919
"os"
20+
"strings"
2021

2122
"github.com/spf13/cobra"
2223
"go.opentelemetry.io/otel"
@@ -47,10 +48,73 @@ Examples:
4748
{{.Example}}{{end}}
4849
`
4950

51+
const rootExample = `
52+
### Using keychain secrets in containers
53+
54+
Create a secret:
55+
56+
` + "```" + `console
57+
$ docker pass set GH_TOKEN=123456789
58+
` + "```" + `
59+
60+
Create a secret from STDIN:
61+
62+
` + "```" + `console
63+
echo "my_val" | docker pass set GH_TOKEN
64+
` + "```" + `
65+
66+
Run a container that uses the secret:
67+
68+
` + "```" + `console
69+
$ docker run -e GH_TOKEN= -dt --name demo busybox
70+
` + "```" + `
71+
72+
Inspect the secret from inside the container:
73+
74+
` + "```" + `console
75+
$ docker exec demo sh -c 'echo $GH_TOKEN'
76+
123456789
77+
` + "```" + `
78+
79+
Explicitly assign a secret to a different environment variable:
80+
81+
` + "```" + `console
82+
$ docker run -e GITHUB_TOKEN=se://GH_TOKEN -dt --name demo busybox
83+
` + "```" + `
84+
85+
### Using keychain secrets in Compose
86+
87+
Store the secrets:
88+
89+
` + "```" + `console
90+
$ docker pass set myapp/anthropic/api-key=sk-ant-...
91+
$ docker pass set myapp/postgres/password=s3cr3t
92+
` + "```" + `
93+
94+
` + "```" + `yaml
95+
services:
96+
api:
97+
image: service1
98+
environment:
99+
- ANTHROPIC_API_KEY=se://myapp/anthropic/api-key
100+
- POSTGRES_PASSWORD=se://myapp/postgres/password
101+
102+
worker:
103+
image: service2
104+
command: worker
105+
environment:
106+
- ANTHROPIC_API_KEY=se://myapp/anthropic/api-key
107+
108+
db:
109+
image: postgres:17
110+
environment:
111+
- POSTGRES_PASSWORD=se://myapp/postgres/password
112+
` + "```"
113+
50114
// Root returns the root command for the docker-pass CLI plugin
51115
func Root(ctx context.Context, s store.Store, info commands.VersionInfo) *cobra.Command {
52116
cmd := &cobra.Command{
53-
Use: "pass [OPTIONS]",
117+
Use: "pass set|get|ls|rm",
54118
Short: "Manage your local OS keychain secrets.",
55119
Long: `Docker Pass is an experimental utility for managing secrets in your
56120
local OS keychain. Secrets are stored using platform-specific credential
@@ -61,6 +125,7 @@ storage:
61125
- Linux: org.freedesktop.secrets API (requires DBus + gnome-keyring or kdewallet)
62126
63127
Secrets can be injected into running containers at runtime using the se:// URI scheme.`,
128+
Example: strings.TrimSpace(rootExample),
64129
SilenceUsage: true,
65130
TraverseChildren: true,
66131
CompletionOptions: cobra.CompletionOptions{

plugins/pass/commands/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
func GetCommand(kc store.Store) *cobra.Command {
2727
cmd := &cobra.Command{
28-
Use: "get",
28+
Use: "get NAME",
2929
Args: cobra.ExactArgs(1),
3030
Short: "Get a secret from a keystore.",
3131
Long: "Retrieves a named secret from the local OS keychain. The secret value is masked in output.",

plugins/pass/commands/rm.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ func RmCommand(kc store.Store) *cobra.Command {
3939
Short: "Remove secrets from local keychain.",
4040
Long: "Removes one or more named secrets from the local OS keychain.\nUse --all to remove every stored secret at once.",
4141
Example: `# Remove a specific secret:
42-
docker pass rm GH_TOKEN
42+
docker pass rm GH_TOKEN
4343
44-
# Remove multiple secrets:
45-
docker pass rm GH_TOKEN NPM_TOKEN
44+
# Remove multiple secrets:
45+
docker pass rm GH_TOKEN NPM_TOKEN
4646
47-
# Remove all secrets:
48-
docker pass rm --all`,
47+
# Remove all secrets:
48+
docker pass rm --all`,
4949
RunE: func(cmd *cobra.Command, args []string) error {
5050
idList, err := validateArgs(args, opts)
5151
if err != nil {

0 commit comments

Comments
 (0)