Skip to main content

image_registry

Function image_registry 

Source
pub fn image_registry(image: &str) -> String
Expand description

Extract the registry hostname from a Docker image reference.

Follows the same rules as the Docker CLI:

  • A bare name like ubuntu or ubuntu:20.04 maps to docker.io.
  • A path without a registry-like first component (e.g. myuser/myimage) maps to docker.io.
  • A first component containing ., :, or equal to localhost is 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");