diff --git a/components/engine/api.go b/components/engine/api.go index 167ed1ad07..136cd52d7c 100644 --- a/components/engine/api.go +++ b/components/engine/api.go @@ -179,23 +179,6 @@ func getContainersChanges(srv *Server, w http.ResponseWriter, r *http.Request) ( return b, nil } -func getContainersPort(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, error) { - if err := r.ParseForm(); err != nil { - return nil, err - } - vars := mux.Vars(r) - name := vars["name"] - out, err := srv.ContainerPort(name, r.Form.Get("port")) - if err != nil { - return nil, err - } - b, err := json.Marshal(ApiPort{out}) - if err != nil { - return nil, err - } - return b, nil -} - func getContainers(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, error) { if err := r.ParseForm(); err != nil { return nil, err @@ -543,7 +526,6 @@ func ListenAndServe(addr string, srv *Server) error { "/images/search": getImagesSearch, "/images/{name:.*}/history": getImagesHistory, "/containers/{name:.*}/changes": getContainersChanges, - "/containers/{name:.*}/port": getContainersPort, "/containers": getContainers, "/images/{name:.*}/json": getImagesByName, "/containers/{name:.*}/json": getContainersByName, diff --git a/components/engine/commands.go b/components/engine/commands.go index 96960455de..02e02d6cec 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -469,19 +469,22 @@ func CmdPort(args ...string) error { cmd.Usage() return nil } - v := url.Values{} - v.Set("port", cmd.Arg(1)) - body, _, err := call("GET", "/containers/"+cmd.Arg(0)+"/port?"+v.Encode(), nil) + + body, _, err := call("GET", "/containers/"+cmd.Arg(0)+"/json", nil) if err != nil { return err } - - var out ApiPort + var out Container err = json.Unmarshal(body, &out) if err != nil { return err } - fmt.Println(out.Port) + + if frontend, exists := out.NetworkSettings.PortMapping[cmd.Arg(1)]; exists { + fmt.Println(frontend) + } else { + return fmt.Errorf("error: No private port '%s' allocated on %s", cmd.Arg(1), cmd.Arg(0)) + } return nil } diff --git a/components/engine/docs/sources/remote-api/api.rst b/components/engine/docs/sources/remote-api/api.rst index 1a430aa010..25007af123 100644 --- a/components/engine/docs/sources/remote-api/api.rst +++ b/components/engine/docs/sources/remote-api/api.rst @@ -265,34 +265,6 @@ Export a container :statuscode 500: server error -Map container's private ports -***************************** - -.. http:get:: /containers/(id)/port - - Map a private port of container ``id`` - - **Example request**: - - .. sourcecode:: http - - GET /containers/4fa6e0f0c678/port?port=80 HTTP/1.1 - - - **Example response**: - - .. sourcecode:: http - - HTTP/1.1 200 OK - - {"Port":"80"} - - :query port: the container private port you want to get - :statuscode 200: no error - :statuscode 404: no such container - :statuscode 500: server error - - Start a container ***************** diff --git a/components/engine/server.go b/components/engine/server.go index 7ba3b68f83..f57d8e6f06 100644 --- a/components/engine/server.go +++ b/components/engine/server.go @@ -235,16 +235,6 @@ func (srv *Server) ContainerChanges(name string) ([]Change, error) { return nil, fmt.Errorf("No such container: %s", name) } -func (srv *Server) ContainerPort(name, privatePort string) (string, error) { - if container := srv.runtime.Get(name); container != nil { - if frontend, exists := container.NetworkSettings.PortMapping[privatePort]; exists { - return frontend, nil - } - return "", fmt.Errorf("No private port '%s' allocated on %s", privatePort, name) - } - return "", fmt.Errorf("No such container: %s", name) -} - func (srv *Server) Containers(all, trunc_cmd, only_ids bool, n int) []ApiContainers { var outs []ApiContainers = []ApiContainers{} //produce [] when empty instead of 'null' for i, container := range srv.runtime.List() {