# Docker Hub API tokens: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/docker-hub
Last checked: 2026-10-25

Docker Hub personal access tokens are created in Docker Home under your avatar → Account settings → Personal access tokens → Generate new token. You choose a repository permission level and an expiry (none, 30 days, 90 days or a custom date up to one year). Use the token as the password for `docker login`; it is shown only once.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Personal access token (PAT) | — | Yes | One repository permission level - Repo Public Read-only (default), Repo Read-only, Repo Read & Write, or Repo Read, Write, Delete - or No repository access; optional Cloud Sandboxes access | Default is none; options are 30 days, 90 days or a custom date up to one year. Expiry cannot be changed afterwards. |

## How to create a Docker Hub key

1. Sign in to Docker Home and verify your email if prompted.
2. Select your avatar, then **Account settings** → **Personal access tokens**.
3. Select **Generate new token**.
4. Choose a repository permission level and an expiration.
5. Generate the token and copy it; Docker shows it only once.

## Limiting what the key can do

Choose the lowest repository permission that works: Repo Public Read-only, Repo Read-only, Repo Read & Write, or Repo Read, Write, Delete. A separate **Allow Cloud Sandboxes access** setting adds the `sandbox:use` scope.

## How to rotate a Docker Hub key

1. Generate a new token with the same permission level.
2. Update the systems that run `docker login` with the old token.
3. Deactivate and then delete the old token from its actions menu.

## How to revoke a Docker Hub key

1. Open **Account settings** → **Personal access tokens** and use the token's actions menu.
2. Choose **Deactivate** (reversible with **Activate**) or **Delete**; expired and revoked tokens can only be deleted.

## If the key leaked

1. Deactivate or delete the token immediately.
2. Generate a replacement with the lowest permission level and a defined expiry.
3. Review the repositories the token could write to for unexpected image pushes or deletions.

## Gotchas

- Docker shows the token once; save it immediately.
- The default permission is Repo Public Read-only, which cannot push; raise it only as needed.
- Docker Desktop can auto-generate up to five tokens and deletes the least recently used when a new one is created.
- Excessive token creation may lead to throttling or additional charges under Docker's fair use policy.

## Using this key with AI agents (BotPassword)

- `list_credentials`: Lists the credentials this agent is granted and what it may do with each. Never values.
- `request_access`: Asks you for a grant, which you approve with your master password or decline in BotPassword on your desktop, never in the chat. The agent gets a receipt, never a value. Approval on your phone is planned.
- `run_with`: Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
- `cli_login`: Lets git, Docker, the AWS CLI and kubectl log in through bpw's credential helper, so the token is fetched when the tool needs it and not written into its config. The helper hands the value to the tool, so the grant is always disclosing. Other tools use run_with; OAuth device logins are planned.
- `rotate`: Partly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet.
- `capture_secret`: Planned, not built yet: will read a newly created key straight from the page or command output into the vault.
- `store_secret`: Saves a value the agent already holds as a new vault item.

## FAQ

### Where do I create a Docker Hub access token?

In Docker Home select your avatar → **Account settings** → **Personal access tokens** → **Generate new token**.

### How do I log in to Docker Hub with an access token?

Run `docker login --username <YOUR_USERNAME>` and paste the token when asked for the password.

### Do Docker Hub access tokens expire?

By default no, but you can choose 30 days, 90 days or a custom date up to one year, and you cannot change it later.

### How do I revoke a Docker Hub access token?

Use the token's actions menu to **Deactivate** it (reversible) or **Delete** it.

### Can an AI agent use my Docker Hub key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a `.env` file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with `list_credentials`, `run_with`, `store_secret`, so the agent gets the result and never the value.

## Sources

- https://docs.docker.com/security/for-developers/access-tokens/
- https://docs.docker.com/security/access-tokens/reference/
