Allow extra lines in /etc/hosts

This adds a --add-host host:ip flag which appends lines to /etc/hosts.  This is needed in places where you want the container to get a different name resolution than it would through DNS.  This was submitted before as #5525, closed, and now I am re-opening.  It has come up 2 or 3 times in the last couple days.

Signed-off-by: Tim Hockin <thockin@google.com>
master
Tim Hockin 2014-09-13 04:35:59 +00:00 committed by Vincent Demeester
parent 8b27eee0f0
commit 4731b1ebc8
1 changed files with 11 additions and 0 deletions

View File

@ -199,6 +199,17 @@ func validateDomain(val string) (string, error) {
return "", fmt.Errorf("%s is not a valid domain", val) return "", fmt.Errorf("%s is not a valid domain", val)
} }
func ValidateExtraHost(val string) (string, error) {
arr := strings.Split(val, ":")
if len(arr) != 2 || len(arr[0]) == 0 {
return "", fmt.Errorf("bad format for add-host: %s", val)
}
if _, err := ValidateIPAddress(arr[1]); err != nil {
return "", fmt.Errorf("bad format for add-host: %s", val)
}
return val, nil
}
// Validates an HTTP(S) registry mirror // Validates an HTTP(S) registry mirror
func ValidateMirror(val string) (string, error) { func ValidateMirror(val string) (string, error) {
uri, err := url.Parse(val) uri, err := url.Parse(val)