2017-02-08 3 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 repository_name의 [version_tag])

:

[registry_hostname의 [포트]/[USER_NAME /] 화상을 식별하기위한 this

현재의 구문 (syntax)에 따라

이런 뭔가

...

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 
} 

(좀 더 세부 사항을 조사 적이 없다하지만)