Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a --add-host host:ip flag which appends lines to /etc/hosts. #5525

Closed
wants to merge 4 commits into from
Closed

Add a --add-host host:ip flag which appends lines to /etc/hosts. #5525

wants to merge 4 commits into from

Conversation

thockin
Copy link
Contributor

@thockin thockin commented May 1, 2014

As per #2335 and #2267 and maybe others, this adds a simple flag to append lines to /etc/hosts.

This is my first foray into go and Docker code, so I'm happy to be told where I screwed it up. I mostly followed the example of the Env flag.

@crosbymichael
Copy link
Contributor

@thockin What is the usecase for doing this?

@thockin
Copy link
Contributor Author

thockin commented May 1, 2014

Specifically I was playing with things Docker can do, and I wanted to be able to identify the host or another container by IP without running DNS. I also wanted to give a name to the bridge endpoint so I could map ports to it without going off-host, mostly to see what I could do with it.

I scanned open issues, and this was a topic of several of them. I wanted an excuse to dig into the code a bit, so I thought I would use this as an excuse to figure things out.

Docker-DCO-1.1-Signed-off-by: Tim Hockin <thockin@google.com> (github: thockin)
Docker-DCO-1.1-Signed-off-by: Tim Hockin <thockin@google.com> (github: thockin)
Docker-DCO-1.1-Signed-off-by: Tim Hockin <thockin@google.com> (github: thockin)
if len(arr) == 2 {
return val, nil
}
return val, fmt.Errorf("bad format for add-host: %s", val)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add the error handling first.

arr := strings.Split(val, """)
if len(arr) != 2 {
   return "", fmt.Errorf(...)
}
return val, nil

Docker-DCO-1.1-Signed-off-by: Tim Hockin <thockin@google.com> (github: thockin)
@crosbymichael
Copy link
Contributor

I think we are going to look into #5129 to solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants