mirror of https://github.com/docker/docs.git
Adds support for `docker inspect` to dockerserver
Signed-off-by: Brian Goff <cpuguy83@gmail.com> (github: cpuguy83)
This commit is contained in:
parent
58da84d474
commit
5c2047af31
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/docker/libswarm/beam"
|
"github.com/docker/libswarm/beam"
|
||||||
"github.com/dotcloud/docker/api"
|
"github.com/dotcloud/docker/api"
|
||||||
"github.com/dotcloud/docker/pkg/version"
|
"github.com/dotcloud/docker/pkg/version"
|
||||||
|
dockerContainerConfig "github.com/dotcloud/docker/runconfig"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"io"
|
"io"
|
||||||
|
@ -13,10 +14,10 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func DockerServer() beam.Sender {
|
func DockerServer() beam.Sender {
|
||||||
|
@ -73,6 +74,68 @@ func ping(out beam.Sender, version version.Version, w http.ResponseWriter, r *ht
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type containerJson struct {
|
||||||
|
Config *dockerContainerConfig.Config
|
||||||
|
HostConfig *dockerContainerConfig.HostConfig
|
||||||
|
ID string
|
||||||
|
Created string
|
||||||
|
Driver string
|
||||||
|
ExecDriver string
|
||||||
|
NetworkSettings struct {
|
||||||
|
Bridge string
|
||||||
|
Gateway string
|
||||||
|
IPAddress string
|
||||||
|
IPPrefixLen int
|
||||||
|
Ports map[string][]map[string]string
|
||||||
|
}
|
||||||
|
State struct {
|
||||||
|
Running bool
|
||||||
|
StartedAt string
|
||||||
|
FinishedAt string
|
||||||
|
ExitCode int
|
||||||
|
Paused bool
|
||||||
|
Pid int
|
||||||
|
}
|
||||||
|
Name string
|
||||||
|
Args []string
|
||||||
|
ProcessLbael string
|
||||||
|
ResolvConfPath string
|
||||||
|
HostnamePath string
|
||||||
|
HostsPath string
|
||||||
|
MountLabel string
|
||||||
|
Volumes map[string]string
|
||||||
|
VolumesRW map[string]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func getContainerJson(out beam.Sender, containerID string) (containerJson, error) {
|
||||||
|
o := beam.Obj(out)
|
||||||
|
|
||||||
|
_, containerOut, err := o.Attach(containerID)
|
||||||
|
if err != nil {
|
||||||
|
return containerJson{}, err
|
||||||
|
}
|
||||||
|
container := beam.Obj(containerOut)
|
||||||
|
responseJson, err := container.Get()
|
||||||
|
if err != nil {
|
||||||
|
return containerJson{}, err
|
||||||
|
}
|
||||||
|
var response containerJson
|
||||||
|
|
||||||
|
if err = json.Unmarshal([]byte(responseJson), &response); err != nil {
|
||||||
|
return containerJson{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getContainerInfo(out beam.Sender, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
|
container, err := getContainerJson(out, vars["name"])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return writeJSON(w, http.StatusOK, container)
|
||||||
|
}
|
||||||
|
|
||||||
func getContainersJSON(out beam.Sender, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func getContainersJSON(out beam.Sender, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -87,36 +150,10 @@ func getContainersJSON(out beam.Sender, version version.Version, w http.Response
|
||||||
var responses []interface{}
|
var responses []interface{}
|
||||||
|
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
_, containerOut, err := o.Attach(name)
|
response, err := getContainerJson(out, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
container := beam.Obj(containerOut)
|
|
||||||
responseJson, err := container.Get()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var response struct {
|
|
||||||
ID string
|
|
||||||
Created string
|
|
||||||
Name string
|
|
||||||
Config struct {
|
|
||||||
Cmd []string
|
|
||||||
Image string
|
|
||||||
}
|
|
||||||
State struct {
|
|
||||||
Running bool
|
|
||||||
StartedAt string
|
|
||||||
FinishedAt string
|
|
||||||
ExitCode int
|
|
||||||
}
|
|
||||||
NetworkSettings struct {
|
|
||||||
Ports map[string][]map[string]string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err = json.Unmarshal([]byte(responseJson), &response); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
created, err := time.Parse(time.RFC3339, response.Created)
|
created, err := time.Parse(time.RFC3339, response.Created)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -334,6 +371,7 @@ func createRouter(out beam.Sender) (*mux.Router, error) {
|
||||||
"GET": {
|
"GET": {
|
||||||
"/_ping": ping,
|
"/_ping": ping,
|
||||||
"/containers/json": getContainersJSON,
|
"/containers/json": getContainersJSON,
|
||||||
|
"/containers/{name}/json": getContainerInfo,
|
||||||
},
|
},
|
||||||
"POST": {
|
"POST": {
|
||||||
"/containers/create": postContainersCreate,
|
"/containers/create": postContainersCreate,
|
||||||
|
|
Loading…
Reference in New Issue