dimicon
Docker Image Icon - A library for fetching Docker image icons from various sources.
Features
- Fetch icons from Docker Hub image logos
- Fetch icons from Docker Hub organization Gravatars
- Fetch icons from devicons/devicon (via jsDelivr CDN, opt-in with
deviconfeature) - Fetch icons from Docker Official Images (via jsDelivr CDN)
- Fetch icons from GitHub Container Registry (via GitHub Avatar)
- Parse Docker image reference strings in various formats
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["rt-multi-thread", "macros"] }
To enable devicons/devicon icon lookup:
[]
= { = "0.1", = ["devicon"] }
Quick Start
use IconService;
async
Supported Registries
| Registry | Icon Source |
|---|---|
Docker Hub (docker.io) |
Official Image logo → Devicon → Image logo → Org Gravatar |
GitHub Container Registry (ghcr.io) |
GitHub Avatar → Devicon |
| Other registries | Devicon |
Image Reference Parsing
The library can parse various Docker image reference formats:
use ImageReference;
// Simple image name
let img = parse?;
assert_eq!;
assert_eq!;
assert_eq!;
// Image with tag
let img = parse?;
assert_eq!;
// User/org image
let img = parse?;
assert_eq!;
// GHCR image
let img = parse?;
assert!;
// Custom registry
let img = parse?;
assert_eq!;
Icon Sources
The IconSource enum represents different icon sources:
use IconSource;
match icon
API Overview
IconService
The main service for fetching image icons.
// Create a new service
let service = new;
// Or with a custom reqwest client
let client = builder
.timeout
.build?;
let service = with_client;
// Fetch icon
let icon = service.get_icon.await?;
ImageReference
Parse and inspect Docker image references.
let img = parse?;
img.is_docker_hub // false
img.is_ghcr // true
img.is_docker_official // false
img.docker_hub_repo_name // "owner/app"
img.full_name // "ghcr.io/owner/app:v1"
Convenience Function
For one-off lookups:
let icon = get_icon.await?;
How It Works
The library fetches icons using the following priority:
-
Registry-specific free sources: Docker Official Image logos (via jsDelivr CDN), GitHub avatars for GHCR images.
-
Devicon: Looks up the image name in the devicons/devicon icon library via jsDelivr CDN. This is a universal fallback that works for any registry.
-
Rate-limited Docker Hub APIs: Image logo, then organization Gravatar via the Docker Hub API. These are tried last to conserve the per-IP rate limit (180 req/hour).
Rate Limiting
Docker Hub APIs have per-IP rate limits. For production use, consider:
- Caching icon URLs
- Using a proxy service like go-camo for image proxying
- Implementing request throttling
Examples
Run the basic example:
Credit
@SukkaW provided the complete idea for this package.
License
MIT License - see LICENSE for details.