pub fn image_registry(image: &str) -> StringExpand description
Extract the registry hostname from a Docker image reference.
Follows the same rules as the Docker CLI:
- A bare name like
ubuntuorubuntu:20.04maps todocker.io. - A path without a registry-like first component (e.g.
myuser/myimage) maps todocker.io. - A first component containing
.,:, or equal tolocalhostis treated as the registry.
Digests (@sha256:...) are stripped before parsing.
ยงExamples
use docker_credentials_config::image_registry;
assert_eq!(image_registry("ubuntu"), "docker.io");
assert_eq!(image_registry("gcr.io/myproject/myimage:latest"), "gcr.io");
assert_eq!(image_registry("localhost:5000/myimage"), "localhost:5000");