diff --git a/api/server/server.go b/api/server/server.go index 9c838c4bbf..25b377ffdb 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -848,6 +848,9 @@ func getContainersByName(eng *engine.Engine, version version.Version, w http.Res return fmt.Errorf("Missing parameter") } var job = eng.Job("container_inspect", vars["name"]) + if version.LessThan("1.12") { + job.SetenvBool("dirty", true) + } streamJSON(job, w, false) return job.Run() } @@ -857,6 +860,9 @@ func getImagesByName(eng *engine.Engine, version version.Version, w http.Respons return fmt.Errorf("Missing parameter") } var job = eng.Job("image_inspect", vars["name"]) + if version.LessThan("1.12") { + job.SetenvBool("dirty", true) + } streamJSON(job, w, false) return job.Run() } diff --git a/daemon/inspect.go b/daemon/inspect.go index 0f771a3ca2..cf70d1579a 100644 --- a/daemon/inspect.go +++ b/daemon/inspect.go @@ -13,14 +13,40 @@ func (daemon *Daemon) ContainerInspect(job *engine.Job) engine.Status { } name := job.Args[0] if container := daemon.Get(name); container != nil { - b, err := json.Marshal(&struct { - *Container - HostConfig *runconfig.HostConfig - }{container, container.HostConfig()}) - if err != nil { + if job.GetenvBool("dirty") { + b, err := json.Marshal(&struct { + *Container + HostConfig *runconfig.HostConfig + }{container, container.HostConfig()}) + if err != nil { + return job.Error(err) + } + job.Stdout.Write(b) + return engine.StatusOK + } + + out := &engine.Env{} + out.Set("Id", container.ID) + out.SetAuto("Created", container.Created) + out.Set("Path", container.Path) + out.SetList("Args", container.Args) + out.SetJson("Config", container.Config) + out.SetJson("State", container.State) + out.Set("Image", container.Image) + out.SetJson("NetworkSettings", container.NetworkSettings) + out.Set("ResolvConfPath", container.ResolvConfPath) + out.Set("HostnamePath", container.HostnamePath) + out.Set("HostsPath", container.HostsPath) + out.Set("Name", container.Name) + out.Set("Driver", container.Driver) + out.Set("ExecDriver", container.ExecDriver) + out.Set("MountLabel", container.MountLabel) + out.Set("ProcessLabel", container.ProcessLabel) + out.SetJson("VolumesRW", container.VolumesRW) + out.SetJson("HostConfig", container.hostConfig) + if _, err := out.WriteTo(job.Stdout); err != nil { return job.Error(err) } - job.Stdout.Write(b) return engine.StatusOK } return job.Errorf("No such container: %s", name) diff --git a/docs/sources/reference/api/docker_remote_api.md b/docs/sources/reference/api/docker_remote_api.md index 84b56866ba..64837817e1 100644 --- a/docs/sources/reference/api/docker_remote_api.md +++ b/docs/sources/reference/api/docker_remote_api.md @@ -36,7 +36,16 @@ You can still call an old version of the api using ### What's new -docker build now has support for the `forcerm` parameter to always remove containers +`POST /build` + +**New!** +Build now has support for the `forcerm` parameter to always remove containers + +`GET /containers/(name)/json` +`GET /images/(name)/json` + +**New!** +All the JSON keys are now in CamelCase ## v1.11 diff --git a/docs/sources/reference/api/docker_remote_api_v1.12.md b/docs/sources/reference/api/docker_remote_api_v1.12.md index 188d4fe0a2..9cc84f4ffc 100644 --- a/docs/sources/reference/api/docker_remote_api_v1.12.md +++ b/docs/sources/reference/api/docker_remote_api_v1.12.md @@ -798,11 +798,9 @@ Return low-level information on the image `name` Content-Type: application/json { - "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", - "parent":"27cf784147099545", - "created":"2013-03-23T22:24:18.818426-07:00", - "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0", - "container_config": + "Created":"2013-03-23T22:24:18.818426-07:00", + "Container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0", + "ContainerConfig": { "Hostname":"", "User":"", @@ -823,6 +821,8 @@ Return low-level information on the image `name` "VolumesFrom":"", "WorkingDir":"" }, + "Id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", + "Parent":"27cf784147099545", "Size": 6824592 } diff --git a/graph/service.go b/graph/service.go index 881a199043..4bce6b5645 100644 --- a/graph/service.go +++ b/graph/service.go @@ -2,7 +2,6 @@ package graph import ( "encoding/json" - "fmt" "io" "github.com/dotcloud/docker/engine" @@ -117,12 +116,12 @@ func (s *TagStore) CmdGet(job *engine.Job) engine.Status { // - Comment: initially created to fulfill the "every image is a git commit" // metaphor, in practice people either ignore it or use it as a // generic description field which it isn't. On deprecation shortlist. - res.Set("created", fmt.Sprintf("%v", img.Created)) - res.Set("author", img.Author) - res.Set("os", img.OS) - res.Set("architecture", img.Architecture) - res.Set("docker_version", img.DockerVersion) - res.Set("ID", img.ID) + res.SetAuto("Created", img.Created) + res.Set("Author", img.Author) + res.Set("Os", img.OS) + res.Set("Architecture", img.Architecture) + res.Set("DockerVersion", img.DockerVersion) + res.Set("Id", img.ID) res.Set("Parent", img.Parent) } res.WriteTo(job.Stdout) @@ -136,11 +135,31 @@ func (s *TagStore) CmdLookup(job *engine.Job) engine.Status { } name := job.Args[0] if image, err := s.LookupImage(name); err == nil && image != nil { - b, err := json.Marshal(image) - if err != nil { + if job.GetenvBool("dirty") { + b, err := json.Marshal(image) + if err != nil { + return job.Error(err) + } + job.Stdout.Write(b) + return engine.StatusOK + } + + out := &engine.Env{} + out.Set("Id", image.ID) + out.Set("Parent", image.Parent) + out.Set("Comment", image.Comment) + out.SetAuto("Created", image.Created) + out.Set("Container", image.Container) + out.SetJson("ContainerConfig", image.ContainerConfig) + out.Set("DockerVersion", image.DockerVersion) + out.Set("Author", image.Author) + out.SetJson("Config", image.Config) + out.Set("Architecture", image.Architecture) + out.Set("Os", image.OS) + out.SetInt64("Size", image.Size) + if _, err = out.WriteTo(job.Stdout); err != nil { return job.Error(err) } - job.Stdout.Write(b) return engine.StatusOK } return job.Errorf("No such image: %s", name) diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index f2bce99cfd..dbec07fab9 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -614,7 +614,7 @@ func TestBuildWithVolume(t *testing.T) { VOLUME /test `, "testbuildimg", - "{{json .config.Volumes}}", + "{{json .Config.Volumes}}", `{"/test":{}}`) deleteImages("testbuildimg") @@ -628,7 +628,7 @@ func TestBuildMaintainer(t *testing.T) { MAINTAINER dockerio `, "testbuildimg", - "{{json .author}}", + "{{json .Author}}", `"dockerio"`) deleteImages("testbuildimg") @@ -644,7 +644,7 @@ func TestBuildUser(t *testing.T) { RUN [ $(whoami) = 'dockerio' ] `, "testbuildimg", - "{{json .config.User}}", + "{{json .Config.User}}", `"dockerio"`) deleteImages("testbuildimg") @@ -664,7 +664,7 @@ func TestBuildRelativeWorkdir(t *testing.T) { RUN [ "$PWD" = '/test2/test3' ] `, "testbuildimg", - "{{json .config.WorkingDir}}", + "{{json .Config.WorkingDir}}", `"/test2/test3"`) deleteImages("testbuildimg") @@ -679,7 +679,7 @@ func TestBuildEnv(t *testing.T) { RUN [ $(env | grep PORT) = 'PORT=4243' ] `, "testbuildimg", - "{{json .config.Env}}", + "{{json .Config.Env}}", `["HOME=/","PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","PORT=4243"]`) deleteImages("testbuildimg") @@ -693,7 +693,7 @@ func TestBuildCmd(t *testing.T) { CMD ["/bin/echo", "Hello World"] `, "testbuildimg", - "{{json .config.Cmd}}", + "{{json .Config.Cmd}}", `["/bin/echo","Hello World"]`) deleteImages("testbuildimg") @@ -708,7 +708,7 @@ func TestBuildExpose(t *testing.T) { `, "testbuildimg", - "{{json .config.ExposedPorts}}", + "{{json .Config.ExposedPorts}}", `{"4243/tcp":{}}`) deleteImages("testbuildimg") @@ -722,7 +722,7 @@ func TestBuildEntrypoint(t *testing.T) { ENTRYPOINT ["/bin/echo"] `, "testbuildimg", - "{{json .config.Entrypoint}}", + "{{json .Config.Entrypoint}}", `["/bin/echo"]`) deleteImages("testbuildimg") diff --git a/integration-cli/docker_cli_tag_test.go b/integration-cli/docker_cli_tag_test.go index d75b7db385..ef51f64644 100644 --- a/integration-cli/docker_cli_tag_test.go +++ b/integration-cli/docker_cli_tag_test.go @@ -27,7 +27,7 @@ func TestTagUnprefixedRepoByName(t *testing.T) { // tagging an image by ID in a new unprefixed repo should work func TestTagUnprefixedRepoByID(t *testing.T) { - getIDCmd := exec.Command(dockerBinary, "inspect", "-f", "{{.id}}", "busybox") + getIDCmd := exec.Command(dockerBinary, "inspect", "-f", "{{.Id}}", "busybox") out, _, err := runCommandWithOutput(getIDCmd) errorOut(err, t, fmt.Sprintf("failed to get the image ID of busybox: %v", err)) diff --git a/integration/commands_test.go b/integration/commands_test.go index 2ee5842e1c..4ad225bb43 100644 --- a/integration/commands_test.go +++ b/integration/commands_test.go @@ -1057,7 +1057,7 @@ func TestContainerOrphaning(t *testing.T) { if err := job.Run(); err != nil { t.Fatal(err) } - return info.Get("ID") + return info.Get("Id") } // build an image