goharbor/harbor · error
login to dockerhub error
Error message
login to dockerhub error: %v
What it means
NewClient performed the initial Docker Hub login (refreshToken) to exchange credentials for a bearer token and it failed; the login error is wrapped, so the adapter client cannot be constructed for authenticated access.
Solutions
- Verify the Docker Hub access key (username) and secret (password/token)
- Check network egress to hub.docker.com from the replication worker
- Inspect the inner error for the precise login failure
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at src/pkg/reg/adapter/dockerhub/client.go:69 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16).
Data as JSON: /api/errors/08effb1ea768e120.
Report an issue: GitHub.
Appendix: source
Thrown at src/pkg/reg/adapter/dockerhub/client.go:69
Timeout: config.RegistryHTTPClientTimeout(),
},
}
// For anonymous access, no need to refresh token.
if registry.Credential == nil ||
(len(registry.Credential.AccessKey) == 0 && len(registry.Credential.AccessSecret) == 0) {
return client, nil
}
// Login to DockerHub to get access token. Tokens expire after 10 minutes;
// subsequent calls via Do() will refresh the token automatically.
client.credential = LoginCredential{
Identifier: registry.Credential.AccessKey,
Secret: registry.Credential.AccessSecret,
}
err := client.refreshToken()
if err != nil {
return nil, fmt.Errorf("login to dockerhub error: %v", err)
}
return client, nil
}
// refreshToken authenticates with Docker Hub via POST /v2/auth/token and stores
// the resulting bearer token. Callers must hold c.mu before calling this method.
func (c *Client) refreshToken() error {
b, err := json.Marshal(c.credential)
if err != nil {
return fmt.Errorf("marshal credential error: %v", err)
}
request, err := http.NewRequest(http.MethodPost, baseURL+loginPath, bytes.NewReader(b))
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/json")View on GitHub (pinned to 7b2fd08cc5)