Skip to content

Commit 6243644

Browse files
add content
1 parent 665007e commit 6243644

File tree

5 files changed

+456
-6
lines changed

5 files changed

+456
-6
lines changed
Lines changed: 181 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,181 @@
1-
Export repositories as list view
2-
For: organizations
1+
---
2+
title: Export organization repositories to CSV
3+
linkTitle: Export repositories
4+
description: Learn how to export a complete list of your organization's Docker Hub repositories using the API.
5+
keywords: docker hub, organization, repositories, export, csv, api, access token
6+
---
7+
8+
This guide shows you how to export a complete list of repositories from your
9+
Docker Hub organization, including private repositories. You'll use an
10+
Organization Access Token (OAT) to authenticate with the Docker Hub API and
11+
export repository details to a CSV file for reporting or analysis.
12+
13+
The exported data includes repository name, visibility status, last updated
14+
date, pull count, and star count.
15+
16+
## Prerequisites
17+
18+
Before you begin, ensure you have:
19+
20+
- Administrator access to a Docker Hub organization
21+
- `curl` installed for making API requests
22+
- `jq` installed for JSON parsing
23+
- A spreadsheet application to view the CSV
24+
25+
## Create an organization access token
26+
27+
Organization access tokens let you authenticate API requests without
28+
interactive login steps.
29+
30+
1. Navigate to your organization in Docker Hub and select **Admin Console**.
31+
32+
2. Select **Access tokens** from the sidebar.
33+
34+
3. Select **Generate access token**.
35+
36+
4. Configure the token permissions:
37+
38+
- Under **Repository permissions**, add every repository you want the
39+
token to access
40+
- Assign at least **Image Pull** (read) access to each repository
41+
- You can add up to 50 repositories per token
42+
43+
5. Copy the generated token and store it securely.
44+
45+
> [!IMPORTANT]
46+
>
47+
> If you only enable **Read public repositories**, the API will only return
48+
> public repositories. To include private repositories in your export, you must
49+
> explicitly add them to the token's repository permissions.
50+
51+
## Authenticate with the Docker Hub API
52+
53+
Exchange your organization access token for a JWT bearer token that you'll use
54+
for subsequent API requests.
55+
56+
1. Set your organization name and access token as variables:
57+
58+
```bash
59+
ORG="<your-org>"
60+
OAT="<your_org_access_token>"
61+
```
62+
63+
2. Call the authentication endpoint to get a JWT:
64+
65+
```bash
66+
TOKEN=$(
67+
curl -s https://hub.docker.com/v2/users/login \
68+
-H 'Content-Type: application/json' \
69+
-d "{\"username\":\"$ORG\",\"password\":\"$OAT\"}" \
70+
| jq -r '.token'
71+
)
72+
```
73+
74+
3. Verify the token was retrieved successfully:
75+
76+
```console
77+
$ echo "Got JWT: ${#TOKEN} chars"
78+
```
79+
80+
You'll use this JWT as a Bearer token in the `Authorization` header for all
81+
subsequent API calls.
82+
83+
## Retrieve all repositories
84+
85+
The Docker Hub API paginates repository lists. This script retrieves all pages
86+
and combines the results.
87+
88+
1. Set the page size and initial API endpoint:
89+
90+
```bash
91+
PAGE_SIZE=100
92+
URL="https://hub.docker.com/v2/namespaces/$ORG/repositories?page_size=$PAGE_SIZE"
93+
```
94+
95+
2. Paginate through all results:
96+
97+
```bash
98+
ALL=$(
99+
while [ -n "$URL" ] && [ "$URL" != "null" ]; do
100+
RESP=$(curl -s "$URL" -H "Authorization: Bearer $TOKEN")
101+
echo "$RESP" | jq -c '.results[]'
102+
URL=$(echo "$RESP" | jq -r '.next')
103+
done | jq -s '.'
104+
)
105+
```
106+
107+
3. Verify the number of repositories retrieved:
108+
109+
```console
110+
$ echo "$ALL" | jq 'length'
111+
```
112+
113+
The script continues requesting the `next` URL from each response until
114+
pagination is complete.
115+
116+
## Export to CSV
117+
118+
Generate a CSV file with repository details that you can open in
119+
spreadsheet applications.
120+
121+
Run the following command to create `repos.csv`:
122+
123+
```bash
124+
echo "$ALL" | jq -r '
125+
(["namespace","name","is_private","last_updated","pull_count","star_count"] | @csv),
126+
(.[] | [
127+
.namespace, .name, .is_private, .last_updated, (.pull_count//0), (.star_count//0)
128+
] | @csv)
129+
' > repos.csv
130+
```
131+
132+
Verify the export completed:
133+
134+
```console
135+
$ echo "Rows:" $(wc -l < repos.csv)
136+
```
137+
138+
Open the `repos.csv` file in your preferred
139+
spreadsheet application to view and analyze your repository data.
140+
141+
## Troubleshooting
142+
143+
### Only public repositories appear
144+
145+
Your organization access token may only have **Read public repositories**
146+
enabled, or it lacks permissions for specific private repositories.
147+
148+
To fix this:
149+
150+
1. Navigate to your organization's access tokens in Docker Hub
151+
2. Select the token you created
152+
3. Add private repositories to the token's permissions with at
153+
least **Image Pull** access
154+
4. Regenerate the JWT and retry the export
155+
156+
### API returns 403 or missing fields
157+
158+
Ensure you're using the JWT from the `/v2/users/login` endpoint as a
159+
Bearer token in the `Authorization` header, not the organization access
160+
token directly.
161+
162+
Verify your authentication:
163+
164+
```console
165+
$ curl -s "https://hub.docker.com/v2/namespaces/$ORG/repositories?page_size=1" \
166+
-H "Authorization: Bearer $TOKEN" | jq
167+
```
168+
169+
If this returns an error, re-run the authentication step to get a fresh JWT.
170+
171+
### Need access to all repositories
172+
173+
Organization access tokens are scoped to specific repositories you select
174+
during token creation. To export all repositories, you have two options:
175+
176+
1. Add all repositories to the organization access token (up to 50 repositories)
177+
2. Use a Personal Access Token (PAT) from an administrator account that has
178+
access across the entire organization
179+
180+
The choice between these approaches depends on your organization's security
181+
policies.

0 commit comments

Comments
 (0)