From 4731b1ebc867755333a21525630bf002cf48e74f Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 13 Sep 2014 04:35:59 +0000 Subject: [PATCH] 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 --- opts/opts.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/opts/opts.go b/opts/opts.go index f57ef8b6d1..4ca7ec58ce 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -199,6 +199,17 @@ func validateDomain(val string) (string, error) { 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 func ValidateMirror(val string) (string, error) { uri, err := url.Parse(val)