2017-02-08 9 views
1

カノニカルドッカー画像タグの形式である:解析ドッカー画像タグ

[[registry-address]:port/]name:tag 

アドレスとポートがドッカーがドッカーハブデフォルトのレジストリに進み、その場合、省略することができます。たとえば、次のすべてが有効です。

ubuntu:latest 
nixos/nix:1.10 
localhost:5000/myfirstimage:latest 
localhost:5000/nixos/nix:latest 

この文字列を確実にコンポーネントの部分に解析するコードが必要です。しかし、 "名前"コンポーネントにスラッシュを含めることができるため、これを明確にすることは不可能です。たとえば、次のタグがあいまいです:

localhost/myfirstimage:latest 

これはドッカーハブの名前localhost/myfirstimageとイメージすることができ、またはそれはアドレスlocalhostで実行されているレジストリ上の名前myfirstimageを持つ画像である可能性があります。

誰かがDocker自身がそのような入力をどのように解析するのか知っていますか?

+1

[この質問](HTTP: //stackoverflow.com/q/37861791/596285)が役に立つかもしれません。 – BMitch

答えて

0

私はそれが確かにあいまいに解析されると信じています。 (:| image_idはリポジトリ名の[version_tag])

[registry_hostname [:ポート] /] [USER_NAME /】画像を識別するためthis

現在の構文に従って

はこのようなものです

...

localhostは、唯一の単一名ホストです。あなたがドッカー場合は、画像識別子はlocalhostのから始まることを意味実際には、複数の部品(「foo.bar」、そう含む「」)を

:その他のポート(「」)のいずれかを含める必要があります、それはローカルホストで実行されているレジストリに対して解決されます:80

>docker pull localhost/myfirstimage:latest 
Pulling repository localhost/myfirstimage 
Error while pulling image: Get http://localhost/v1/repositories/myfirstimage/images: dial tcp 127.0.0.1:80: getsockopt: connection refused 

(ドッカー1.12.0でテスト済み)

同じのために ""

>docker pull a.myfirstimage/name:latest 
Using default tag: latest 
Error response from daemon: Get https://a.myfirstimage/v1/_ping: dial tcp: lookup a.myfirstimage on 127.0.0.1:53: no such host 

":"

>docker pull myfirstimage:80/name:latest 
Error response from daemon: Get https://myfirstimage:80/v1/_ping: dial tcp: lookup myfirstimage on 127.0.0.1:53: no such host 

だからあなた解析コードは最初"/"前の部分文字列を見て、それが"localhost" をであるかどうかを確認する必要があり、または"が含まれています。 ":XYZ"(ポート番号)。この場合はregistry_hostnameです。そうでない場合はリポジトリ名(username/repository_name)です。

これを実装ドッカーコードは、ここにあるように見える。(私は詳細でそれを調査していませんでしたが) reference.goservice.go

// splitReposSearchTerm breaks a search term into an index name and remote name 
func splitReposSearchTerm(reposName string) (string, string) { 
     nameParts := strings.SplitN(reposName, "/", 2) 
     var indexName, remoteName string 
     if len(nameParts) == 1 || (!strings.Contains(nameParts[0], ".") && 
       !strings.Contains(nameParts[0], ":") && nameParts[0] != "localhost") { 
       // This is a Docker Index repos (ex: samalba/hipache or ubuntu) 
       // 'docker.io' 
       indexName = IndexName 
       remoteName = reposName 
     } else { 
       indexName = nameParts[0] 
       remoteName = nameParts[1] 
     } 
     return indexName, remoteName 
} 

関連する問題