-
-
Notifications
You must be signed in to change notification settings - Fork 466
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
[Feature] Docker machine #71
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package run | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func getDockerMachineIp() (string, error) { | ||
machine := os.ExpandEnv("$DOCKER_MACHINE_NAME") | ||
|
||
if machine == "" { | ||
return "", nil | ||
} | ||
|
||
dockerMachinePath, err := exec.LookPath("docker-machine") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. It worked for me since I tested using the shell provided by docker toolbox on windows. Do you mind send a PR that implements this idea? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to this patch, exec.LookPath() on windows should attempt to find executables with .exe or .com extensions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the info. Seems like fairly simple but personally I never used Go before so I'll leave it to others. |
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
out, err := exec.Command(dockerMachinePath, "ip", machine).Output() | ||
|
||
ipStr := strings.TrimSuffix(string(out), "\n") | ||
ipStr = strings.TrimSuffix(ipStr, "\r") | ||
return ipStr, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think calling
docker-machine active
to get the machine name would be more reliable as environmental variables might not be set or overridden by users.Also we're calling
docker-machine ip
instead of DOCKER_HOST already anyways.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried doing
docker-machine active
and didn't get any output (even though one of the machines is running). I am not familiar with this command can you describe more of what needs to be done ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting. Mine outputs
default
and the explanation is thatWhat's your output of
docker-machine env
? Does it have the following line?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Output for
docker-machine env dvm
"dvm" is the name of the docker-machineThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
docker-machine ls
Does "dvm" line has an active mark on the left?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's really strange then.
docker-machine ls
reportsdvm
is active whiledocker-machine active
reports nothing is active. I can't think of anything else than it's a docker-machine bug.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to find similar issues in their repo. docker/machine#1651 docker/machine#3448
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, definitely that issue. What do you suggest ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I guess we don't have any choice other than DOCKER_HOST. I just looked up their active check, and it's also just a combination of [DOCKER_HOST + current status] https://github.com/docker/machine/blob/19973f2b1bbcb7b1c07a3de572177bcaf8dedcd5/commands/ls.go#L490
Also, docker-machine repository hasn't been updated for several months so we can't expect it to be fixed anytime soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we should leave it like this for now or create a new issue regarding this.