@@ -28,21 +28,51 @@ description: |-
28
28
29
29
Authentication
30
30
We have multiple ways to set your Docker credentials.
31
- Setting credentials
32
- Use docker login to log in to aregistry https://docs.docker.com/reference/cli/docker/login/. The docker CLI
31
+ Setting credentials with docker login
32
+ To login in an interactive command-line:
33
+
34
+ docker login
35
+
36
+ To login in a non-interactive script:
37
+
38
+ cat ~/my_password.txt | docker login --username my-username --password-stdin
39
+
40
+ The docker CLI
33
41
will store your credentials securely in your credential store, such as the
34
42
operating system native keychain. The Docker Terraform provider will
35
43
use these credentials automatically.
44
+ Setting credentials in CI
45
+ The Docker Terraform provider will work with your CI provider's
46
+ native Docker login action. For example, in GitHub Actions https://github.com/marketplace/actions/docker-login:
36
47
37
- cat ~/my_password.txt | docker login --username my-username --password-stdin
48
+ jobs:
49
+ login:
50
+ runs-on: ubuntu-latest
51
+ steps:
52
+ - name: Login to Docker Hub
53
+ uses: docker/login-action@v3
54
+ with:
55
+ username: ${{ vars.DOCKERHUB_USERNAME }}
56
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
38
57
58
+ Setting credentials with environment variables
39
59
If you'd like to use a different account for running the provider,
40
60
you can set credentials in the environment:
41
61
42
62
export DOCKER_USERNAME=my-username
43
63
export DOCKER_PASSWORD=my-secret-token
44
64
terraform plan ...
45
65
66
+ Setting credentials in Terraform (NOT RECOMMENDED)
67
+ [!WARNING]Hard-coding secrets in Terraform is risky. You risk leaking the secretsif they're committed to version control.
68
+ Only pass in a password in Terraform if you're pulling the secret from a secure
69
+ location, or if you're doing local testing.
70
+
71
+ provider "docker" {
72
+ username = "my-username"
73
+ password = "my-secret-token"
74
+ }
75
+
46
76
Credential types
47
77
You can create a personal access token (PAT) to use as an alternative to your
48
78
password for Docker CLI authentication.
@@ -90,18 +120,44 @@ resource "docker_repository" "example" {
90
120
91
121
We have multiple ways to set your Docker credentials.
92
122
93
- ### Setting credentials
123
+ ### Setting credentials with ` docker login `
124
+
125
+ To login in an interactive command-line:
126
+
127
+ ```
128
+ docker login
129
+ ```
130
+
131
+ To login in a non-interactive script:
132
+
133
+ ```
134
+ cat ~/my_password.txt | docker login --username my-username --password-stdin
135
+ ```
94
136
95
- Use ` docker login ` to [ log in to a
96
- registry] ( https://docs.docker.com/reference/cli/docker/login/ ) . The ` docker ` CLI
137
+ The ` docker ` CLI
97
138
will store your credentials securely in your credential store, such as the
98
139
operating system native keychain. The Docker Terraform provider will
99
140
use these credentials automatically.
100
141
142
+ ### Setting credentials in CI
143
+
144
+ The Docker Terraform provider will work with your CI provider's
145
+ native Docker login action. For example, in [ GitHub Actions] ( https://github.com/marketplace/actions/docker-login ) :
146
+
101
147
```
102
- cat ~/my_password.txt | docker login --username my-username --password-stdin
148
+ jobs:
149
+ login:
150
+ runs-on: ubuntu-latest
151
+ steps:
152
+ - name: Login to Docker Hub
153
+ uses: docker/login-action@v3
154
+ with:
155
+ username: ${{ vars.DOCKERHUB_USERNAME }}
156
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
103
157
```
104
158
159
+ ### Setting credentials with environment variables
160
+
105
161
If you'd like to use a different account for running the provider,
106
162
you can set credentials in the environment:
107
163
@@ -111,6 +167,22 @@ export DOCKER_PASSWORD=my-secret-token
111
167
terraform plan ...
112
168
```
113
169
170
+ ### Setting credentials in Terraform (NOT RECOMMENDED)
171
+
172
+ > [ !WARNING]
173
+ > Hard-coding secrets in Terraform is risky. You risk leaking the secrets
174
+ > if they're committed to version control.
175
+
176
+ Only pass in a password in Terraform if you're pulling the secret from a secure
177
+ location, or if you're doing local testing.
178
+
179
+ ``` hcl
180
+ provider "docker" {
181
+ username = "my-username"
182
+ password = "my-secret-token"
183
+ }
184
+ ```
185
+
114
186
### Credential types
115
187
116
188
You can create a personal access token (PAT) to use as an alternative to your
@@ -134,4 +206,5 @@ this provider to manage organizations and teams, you will need to authenticate
134
206
### Optional
135
207
136
208
- ` host ` (String) Docker Hub API Host. Default is ` hub.docker.com ` .
209
+ - ` password ` (String, Sensitive) Password for authentication
137
210
- ` username ` (String) Username for authentication
0 commit comments