-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.html
More file actions
805 lines (731 loc) · 31.4 KB
/
Copy pathindex.html
File metadata and controls
805 lines (731 loc) · 31.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="Download Docker images as files. Useful if you are located in places where DockerHub is blocked."
/>
<meta
name="keywords"
content="download docker image, download docker image as file, docker image download, download docker image tar, offline docker images, docker save download, download image from Docker Hub, download container image, dockerhub download file, download docker images without docker pull, docker cuba, docker iran, docker china, download docker images when DockerHub is blocked"
/>
<title>Download Docker images</title>
<link rel="icon" href="/logo.png" type="image/png" />
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
background-color: #fff;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
.logo {
margin-bottom: 28px;
}
.logo img {
height: 92px;
}
.search-box {
display: flex;
flex-direction: column;
align-items: center;
}
.search-wrapper {
display: flex;
align-items: center;
width: 584px;
max-width: 90vw;
height: 44px;
border: 1px solid #dfe1e5;
border-radius: 24px;
padding: 0 14px;
margin-bottom: 18px;
}
.search-wrapper:hover,
.search-wrapper:focus-within {
box-shadow: 0 1px 6px rgba(32, 33, 36, 0.28);
border-color: rgba(223, 225, 229, 0);
}
.search-input {
flex: 1;
border: none;
outline: none;
font-size: 16px;
background: transparent;
}
.platform-row {
display: none;
align-items: center;
gap: 8px;
margin-bottom: 16px;
flex-wrap: wrap;
justify-content: center;
}
.platform-row.visible {
display: flex;
}
.platform-label {
font-size: 13px;
color: #5f6368;
}
.platform-select {
height: 32px;
padding: 0 8px;
font-size: 13px;
border: 1px solid #dfe1e5;
border-radius: 4px;
color: #3c4043;
background-color: #fff;
cursor: pointer;
outline: none;
}
.platform-select:focus {
border-color: #4285f4;
box-shadow: 0 0 0 1px #4285f4;
}
.buttons {
display: flex;
gap: 12px;
}
.btn {
height: 36px;
padding: 0 16px;
font-size: 14px;
background-color: #f8f9fa;
border: 1px solid #f8f9fa;
border-radius: 4px;
color: #3c4043;
cursor: pointer;
}
.btn:hover {
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
background-color: #f8f9fa;
border: 1px solid #dadce0;
color: #202124;
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.btn-primary {
background-color: #4285f4;
border-color: #4285f4;
color: #fff;
}
.btn-primary:hover {
background-color: #3b78e7;
border-color: #3b78e7;
color: #fff;
box-shadow: 0 1px 3px rgba(66, 133, 244, 0.4);
}
.status {
margin-top: 20px;
text-align: center;
color: #5f6368;
font-size: 14px;
min-height: 24px;
}
.status.error {
color: #d93025;
}
.error-box {
margin-top: 20px;
padding: 16px;
background-color: #fce8e6;
border-radius: 8px;
border-left: 4px solid #d93025;
max-width: 500px;
text-align: left;
}
.error-box .error-title {
font-weight: bold;
color: #d93025;
margin-bottom: 8px;
font-size: 14px;
}
.error-box .error-message {
color: #5f6368;
font-size: 13px;
word-break: break-word;
}
.error-box .error-detail {
margin-top: 8px;
padding-top: 8px;
border-top: 1px solid #f5c6cb;
color: #80868b;
font-size: 12px;
font-family: monospace;
}
.spinner {
display: inline-block;
width: 16px;
height: 16px;
border: 2px solid #dfe1e5;
border-top-color: #4285f4;
border-radius: 50%;
animation: spin 1s linear infinite;
vertical-align: middle;
margin-right: 8px;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.progress-bar {
width: 300px;
max-width: 90vw;
height: 4px;
background-color: #e0e0e0;
border-radius: 2px;
margin-top: 12px;
overflow: hidden;
display: none;
}
.progress-bar.visible {
display: block;
}
.progress-fill {
height: 100%;
background-color: #4285f4;
border-radius: 2px;
transition: width 0.3s ease;
width: 0;
}
.progress-fill.indeterminate {
width: 30%;
animation: indeterminate 1.5s ease-in-out infinite;
}
@keyframes indeterminate {
0% {
transform: translateX(-100%);
}
100% {
transform: translateX(400%);
}
}
.github-ribbon {
position: absolute;
top: 0;
right: 0;
width: 150px;
height: 150px;
overflow: hidden;
z-index: 1000;
}
.github-ribbon a {
display: block;
width: 200px;
padding: 8px 0;
background-color: #333;
color: #fff;
text-align: center;
font-size: 13px;
font-weight: bold;
text-decoration: none;
position: absolute;
top: 40px;
right: -45px;
transform: rotate(45deg);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
.github-ribbon a:hover {
background-color: #444;
}
</style>
</head>
<body>
<div class="github-ribbon">
<a
href="https://github.com/jadolg/DockerImageSave"
target="_blank"
rel="noopener noreferrer"
>Fork me on GitHub</a
>
</div>
<div class="container">
<div class="logo">
<img
src="/logo.png"
alt="Docker Image Download — save Docker images as files"
/>
</div>
<form class="search-box" id="downloadForm">
<div class="search-wrapper">
<input
type="text"
class="search-input"
id="imageName"
name="name"
placeholder="ubuntu:25.04"
autocomplete="off"
autofocus
/>
</div>
<div class="platform-row" id="platformRow">
<span class="platform-label">OS:</span>
<select class="platform-select" id="osSelect"></select>
<span class="platform-label">Arch:</span>
<select class="platform-select" id="archSelect"></select>
</div>
<div class="buttons">
<button type="button" class="btn" id="detectBtn">
Detect platforms
</button>
<button type="submit" class="btn btn-primary" id="downloadBtn">
Download
</button>
</div>
</form>
<div class="status" id="status"></div>
<div class="progress-bar" id="progressBar">
<div class="progress-fill" id="progressFill"></div>
</div>
</div>
<script>
const form = document.getElementById("downloadForm");
const imageNameInput = document.getElementById("imageName");
const downloadBtn = document.getElementById("downloadBtn");
const detectBtn = document.getElementById("detectBtn");
const platformRow = document.getElementById("platformRow");
const osSelect = document.getElementById("osSelect");
const archSelect = document.getElementById("archSelect");
const status = document.getElementById("status");
const progressBar = document.getElementById("progressBar");
const progressFill = document.getElementById("progressFill");
// Track which image name the current platform dropdowns belong to
let detectedForImage = null;
function hidePlatforms() {
detectedForImage = null;
platformRow.classList.remove("visible");
osSelect.innerHTML = "";
archSelect.innerHTML = "";
}
imageNameInput.addEventListener("input", () => {
hidePlatforms();
});
function parseError(errorMessage) {
// Try to extract meaningful parts from the error
const result = {
title: "Download Failed",
message: errorMessage,
detail: null,
};
// Check for common error patterns — check backend status-based
// messages first, then fall back to registry error codes.
if (errorMessage.includes("image not found")) {
result.title = "Image Not Found";
result.message = "The requested image does not exist.";
} else if (
errorMessage.includes("MANIFEST_UNKNOWN") ||
errorMessage.includes("manifest unknown")
) {
result.title = "Image Not Found";
result.message = "The requested image tag does not exist.";
const tagMatch = errorMessage.match(
/unknown tag=([^\s}"]+)/,
);
if (tagMatch) {
result.detail = `Tag "${tagMatch[1]}" was not found in the registry.`;
}
} else if (
errorMessage.includes("NAME_UNKNOWN") ||
errorMessage.includes("name unknown")
) {
result.title = "Repository Not Found";
result.message = "The requested repository does not exist.";
} else if (errorMessage.includes("access denied")) {
result.title = "Access Denied";
result.message =
"The image may not exist, or you may need credentials to access it.";
} else if (
errorMessage.includes("UNAUTHORIZED") ||
errorMessage.includes("unauthorized")
) {
result.title = "Authentication Required";
result.message =
"You need to be authenticated to access this image.";
} else if (
errorMessage.includes("DENIED") ||
errorMessage.includes("denied")
) {
result.title = "Access Denied";
result.message =
"You do not have permission to access this image.";
} else if (
errorMessage.includes("connection refused") ||
errorMessage.includes("no such host")
) {
result.title = "Connection Error";
result.message =
"Could not connect to the registry server.";
} else if (
errorMessage.includes("timeout") ||
errorMessage.includes("Timeout")
) {
result.title = "Request Timeout";
result.message = "The request took too long to complete.";
} else if (
errorMessage.includes("missing required") ||
(errorMessage.includes("name") &&
errorMessage.includes("parameter"))
) {
result.title = "Missing Image Name";
result.message =
"Please provide an image name to download.";
} else if (
errorMessage.includes("image name cannot be empty")
) {
result.title = "Invalid Image Name";
result.message = "Image name cannot be empty.";
} else if (errorMessage.includes("image name too long")) {
result.title = "Invalid Image Name";
result.message =
"Image name is too long (maximum 256 characters).";
} else if (
errorMessage.includes("invalid characters") ||
errorMessage.includes("contains invalid characters")
) {
result.title = "Invalid Image Name";
result.message = "Image name contains invalid characters.";
} else if (errorMessage.includes("invalid image name")) {
result.title = "Invalid Image Name";
result.message = "The image name format is not valid.";
// Extract the specific reason
const reasonMatch = errorMessage.match(
/invalid image name:\s*(.+)/i,
);
if (reasonMatch) {
result.detail = reasonMatch[1];
}
} else if (errorMessage.includes("authentication failed")) {
result.title = "Authentication Failed";
result.message =
"Failed to authenticate with the registry.";
// Try to extract status code
const statusMatch = errorMessage.match(/(\d{3})\s*-/);
if (statusMatch) {
result.detail = `Server returned status ${statusMatch[1]}`;
}
} else if (
errorMessage.includes("no WWW-Authenticate header")
) {
result.title = "Registry Error";
result.message =
"The registry did not provide authentication information.";
} else if (errorMessage.includes("unexpected status")) {
result.title = "Registry Error";
result.message =
"Received an unexpected response from the registry.";
const statusMatch = errorMessage.match(
/unexpected status:\s*(\d+)/,
);
if (statusMatch) {
result.detail = `Status code: ${statusMatch[1]}`;
}
} else if (errorMessage.includes("failed to get manifest")) {
result.title = "Manifest Error";
result.message =
"Could not retrieve the image manifest from the registry.";
// Try to extract status code
const statusMatch = errorMessage.match(/(\d{3})\s*-/);
if (statusMatch) {
result.detail = `Server returned status ${statusMatch[1]}`;
}
} else if (
errorMessage.includes("no manifest found for platform")
) {
result.title = "Platform Not Available";
result.message =
"This image does not support the selected platform.";
result.detail =
'Use "Detect platforms" to see what is available.';
} else if (errorMessage.includes("failed to download config")) {
result.title = "Download Error";
result.message =
"Failed to download the image configuration.";
} else if (errorMessage.includes("failed to download layer")) {
result.title = "Download Error";
result.message =
"Failed to download one of the image layers.";
} else if (errorMessage.includes("failed to decompress")) {
result.title = "Processing Error";
result.message = "Failed to decompress the image layer.";
} else if (errorMessage.includes("failed to create tar")) {
result.title = "Processing Error";
result.message =
"Failed to create the final image archive.";
} else {
// Try to extract a cleaner message from JSON error response
const jsonMatch = errorMessage.match(/\d+\s*-\s*(\{.+\})/);
if (jsonMatch) {
try {
const parsed = JSON.parse(jsonMatch[1]);
if (parsed.errors && parsed.errors[0]) {
result.message =
parsed.errors[0].message || errorMessage;
if (parsed.errors[0].detail) {
result.detail =
typeof parsed.errors[0].detail ===
"string"
? parsed.errors[0].detail
: JSON.stringify(
parsed.errors[0].detail,
);
}
}
} catch (e) {
// Keep original message
}
}
}
return result;
}
function setStatusWithSpinner(text) {
while (status.firstChild) {
status.removeChild(status.firstChild);
}
const spinner = document.createElement("span");
spinner.className = "spinner";
status.appendChild(spinner);
status.appendChild(document.createTextNode(text));
}
function showError(errorMessage) {
const error = parseError(errorMessage);
while (status.firstChild) {
status.removeChild(status.firstChild);
}
status.classList.remove("error");
const errorBox = document.createElement("div");
errorBox.className = "error-box";
const titleDiv = document.createElement("div");
titleDiv.className = "error-title";
titleDiv.textContent = error.title;
errorBox.appendChild(titleDiv);
const messageDiv = document.createElement("div");
messageDiv.className = "error-message";
messageDiv.textContent = error.message;
errorBox.appendChild(messageDiv);
if (error.detail) {
const detailDiv = document.createElement("div");
detailDiv.className = "error-detail";
detailDiv.textContent = error.detail;
errorBox.appendChild(detailDiv);
}
status.appendChild(errorBox);
}
detectBtn.addEventListener("click", async () => {
const imageName = imageNameInput.value.trim();
if (!imageName) {
status.textContent = "Please enter an image name first";
status.classList.add("error");
return;
}
status.classList.remove("error");
setStatusWithSpinner("Detecting available platforms...");
detectBtn.disabled = true;
hidePlatforms();
try {
const response = await fetch(
`/platforms?name=${encodeURIComponent(imageName)}`,
);
const data = await response.json();
if (!response.ok) {
showError(data.error || "Failed to detect platforms");
return;
}
const allPlatforms = data.platforms;
const platforms = (allPlatforms || []).filter(
(p) => p.os && p.os !== "unknown" && p.architecture && p.architecture !== "unknown",
);
if (platforms.length === 0) {
status.textContent =
"Single-arch image — no platform selection needed.";
return;
}
// Populate selects with only the detected platforms
const osValues = [...new Set(platforms.map((p) => p.os))];
const archValues = [
...new Set(
platforms.map((p) =>
p.variant
? p.architecture + "/" + p.variant
: p.architecture,
),
),
];
osSelect.innerHTML = "";
osValues.forEach((o) => {
const opt = document.createElement("option");
opt.value = o;
opt.textContent = o;
osSelect.appendChild(opt);
});
archSelect.innerHTML = "";
archValues.forEach((a) => {
const opt = document.createElement("option");
opt.value = a;
opt.textContent = a;
archSelect.appendChild(opt);
});
detectedForImage = imageName;
platformRow.classList.add("visible");
status.textContent = "";
} catch (error) {
showError(error.message);
} finally {
detectBtn.disabled = false;
}
});
form.addEventListener("submit", async (e) => {
e.preventDefault();
const imageName = imageNameInput.value.trim();
if (!imageName) {
status.textContent = "Please enter an image name";
status.classList.add("error");
return;
}
// Only include platform params if dropdowns were detected for this exact image
let url = `/image?name=${encodeURIComponent(imageName)}`;
if (detectedForImage === imageName) {
const selectedOS = osSelect.value;
const selectedArch = archSelect.value;
// Split arch into architecture and variant (e.g. "arm/v7" → arch=arm, variant=v7)
const archParts = selectedArch.split("/");
const arch = archParts[0];
const variant = archParts[1] || "";
url += `&os=${encodeURIComponent(selectedOS)}&arch=${encodeURIComponent(arch)}`;
if (variant) {
url += `&variant=${encodeURIComponent(variant)}`;
}
}
// Reset and show progress
status.classList.remove("error");
setStatusWithSpinner("Preparing download...");
progressBar.classList.add("visible");
progressFill.style.width = "0%";
progressFill.classList.add("indeterminate");
downloadBtn.disabled = true;
detectBtn.disabled = true;
try {
const response = await fetch(url);
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || "Download failed");
}
// Get content length for progress
const contentLength =
response.headers.get("Content-Length");
const totalBytes = contentLength
? parseInt(contentLength, 10)
: 0;
// Get filename from Content-Disposition header
const disposition = response.headers.get(
"Content-Disposition",
);
let filename = "image.tar.gz";
if (disposition) {
const match = disposition.match(/filename="(.+)"/);
if (match) {
// Sanitize filename: only allow alphanumeric, dash, underscore, dot
let sanitized = match[1]
.replace(/[^a-zA-Z0-9._-]/g, "_") // Replace unsafe chars with underscore
.replace(/^\.+/, "") // Remove leading dots
.substring(0, 255); // Limit length
// Validate the result matches expected pattern
if (
sanitized &&
/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(sanitized)
) {
filename = sanitized;
}
}
}
// Read the response as a stream to track progress
const reader = response.body.getReader();
const chunks = [];
let receivedBytes = 0;
progressFill.classList.remove("indeterminate");
setStatusWithSpinner("Downloading...");
while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
receivedBytes += value.length;
if (totalBytes > 0) {
const rawPercent = Math.round(
(receivedBytes / totalBytes) * 100,
);
const percent = Number.isFinite(rawPercent)
? Math.min(100, Math.max(0, rawPercent))
: 0;
progressFill.style.width = String(percent) + "%";
const rawSizeMB = receivedBytes / (1024 * 1024);
const rawTotalMB = totalBytes / (1024 * 1024);
const sizeMB = Number.isFinite(rawSizeMB)
? rawSizeMB.toFixed(1)
: "0.0";
const totalMB = Number.isFinite(rawTotalMB)
? rawTotalMB.toFixed(1)
: "0.0";
setStatusWithSpinner(
"Downloading... " +
sizeMB +
" MB / " +
totalMB +
" MB (" +
percent +
"%)",
);
} else {
const rawSizeMB = receivedBytes / (1024 * 1024);
const sizeMB = Number.isFinite(rawSizeMB)
? rawSizeMB.toFixed(1)
: "0.0";
setStatusWithSpinner(
"Downloading... " + sizeMB + " MB",
);
}
}
// Create blob and trigger download
const blob = new Blob(chunks);
const blobUrl = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = blobUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(blobUrl);
imageNameInput.value = "";
hidePlatforms();
const finalSizeMB = (receivedBytes / (1024 * 1024)).toFixed(1);
status.textContent = `Download complete! (${finalSizeMB} MB)`;
progressBar.classList.remove("visible");
progressFill.style.width = "0%";
} catch (error) {
showError(error.message);
progressBar.classList.remove("visible");
} finally {
downloadBtn.disabled = false;
detectBtn.disabled = false;
}
});
</script>
</body>
</html>