import ( "github.com/docker/distribution/reference" "fmt" ) func main() { ref, err := reference.ParseNormalizedNamed("docker.io/library/ubuntu:latest") if err != nil { fmt.Println("Error parsing reference:", err) return } fmt.Println("Registry:", reference.Domain(ref)) fmt.Println("Repository:", reference.Path(ref)) fmt.Println("Tag:", reference.Tag(ref)) }
Registry: docker.io Repository: library/ubuntu Tag: latest
import ( "github.com/docker/distribution/reference" "fmt" ) func main() { repo := "myusername/myimage" tag := "v1.0.0" ref, err := reference.Named(fmt.Sprintf("%s:%s", repo, tag)) if err != nil { fmt.Println("Error creating named reference:", err) return } fmt.Println("Registry:", reference.Domain(ref)) fmt.Println("Repository:", reference.Path(ref)) fmt.Println("Tag:", reference.Tag(ref)) }
Registry: Repository: myusername/myimage Tag: v1.0.0Overall, the github.com/docker/distribution/reference package in Go is a useful tool for working with Docker images and identifying them using named references.