Created
June 15, 2015 07:54
-
-
Save aboch/a0e811367f9269a8e81f to your computer and use it in GitHub Desktop.
lookupContainerID changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/client/service.go b/client/service.go | |
index e2285d7..cd085a0 100644 | |
--- a/client/service.go | |
+++ b/client/service.go | |
@@ -8,6 +8,7 @@ import ( | |
"strings" | |
"text/tabwriter" | |
+ "github.com/docker/docker/api/types" | |
flag "github.com/docker/docker/pkg/mflag" | |
"github.com/docker/docker/pkg/stringid" | |
) | |
@@ -92,8 +93,21 @@ func lookupServiceID(cli *NetworkCli, nwName, svNameID string) (string, error) { | |
} | |
func lookupContainerID(cli *NetworkCli, cnNameID string) (string, error) { | |
- // TODO : containerID to sandbox-key ? | |
- return cnNameID, nil | |
+ // Container is a Docker resource, ask docker about it. | |
+ // In case of connecton error, we assume we are running in dnet and return wathever was passed to us | |
+ obj, _, err := readBody(cli.call("GET", fmt.Sprintf("1.19/containers/%s/json", cnNameID), nil, nil)) | |
+ if err != nil { | |
+ // We are probably running outside of docker | |
+ return cnNameID, nil | |
+ } | |
+ | |
+ var reply types.ContainerJSON | |
+ err = json.Unmarshal(obj, &reply) | |
+ if err != nil { | |
+ return "", err | |
+ } | |
+ | |
+ return reply.Id, nil | |
} | |
// CmdService handles the service UI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment