Developer tools

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

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.

Docker Hub key types

TypePrefixSecret?ScopeExpiry
Personal access token (PAT)
The documentation pages used do not state a token prefix.
—YesOne 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 accessDefault 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.

You cannot change the expiration of an existing token; create a new one instead.

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 your Docker Hub 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.

Environment variables and CLI

Docker CLI (docker): docker login --username <YOUR_USERNAME> and paste the personal access token when prompted for the password

Things that catch people out

  • 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.

Recent incidents that put Docker Hub keys at risk

If you were affected by one of these, rotate your Docker Hub keys using the rotation steps above.

Using your Docker Hub key with AI agents

A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.

BotPassword works this way. For a Docker Hub key, these intents fit:

IntentWhat BotPassword does
list_credentialsLists the credentials this agent is granted and what it may do with each. Never values.
request_accessAsks 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_withRuns 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_loginLets 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.
rotatePartly 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_secretPlanned, not built yet: will read a newly created key straight from the page or command output into the vault.
store_secretSaves a value the agent already holds as a new vault item.

Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents

Frequently asked questions

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.

Stop pasting Docker Hub keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.