1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #15472 from coolljt0725/fix_docker_ps_trucate_id

Fix docker ps truncate long image name
This commit is contained in:
Vincent Demeester 2015-10-02 18:56:55 +01:00
commit 830729bb94
6 changed files with 31 additions and 4 deletions

View file

@ -62,8 +62,10 @@ func (c *containerContext) Image() string {
return "<no image>" return "<no image>"
} }
if c.trunc { if c.trunc {
if stringid.TruncateID(c.c.ImageID) == stringid.TruncateID(c.c.Image) {
return stringutils.Truncate(c.c.Image, 12) return stringutils.Truncate(c.c.Image, 12)
} }
}
return c.c.Image return c.c.Image
} }

View file

@ -26,8 +26,26 @@ func TestContainerPsContext(t *testing.T) {
{types.Container{ID: containerID}, false, containerID, idHeader, ctx.ID}, {types.Container{ID: containerID}, false, containerID, idHeader, ctx.ID},
{types.Container{Names: []string{"/foobar_baz"}}, true, "foobar_baz", namesHeader, ctx.Names}, {types.Container{Names: []string{"/foobar_baz"}}, true, "foobar_baz", namesHeader, ctx.Names},
{types.Container{Image: "ubuntu"}, true, "ubuntu", imageHeader, ctx.Image}, {types.Container{Image: "ubuntu"}, true, "ubuntu", imageHeader, ctx.Image},
{types.Container{Image: "verylongimagename"}, true, "verylongimag", imageHeader, ctx.Image}, {types.Container{Image: "verylongimagename"}, true, "verylongimagename", imageHeader, ctx.Image},
{types.Container{Image: "verylongimagename"}, false, "verylongimagename", imageHeader, ctx.Image}, {types.Container{Image: "verylongimagename"}, false, "verylongimagename", imageHeader, ctx.Image},
{types.Container{
Image: "a5a665ff33eced1e0803148700880edab4",
ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5",
},
true,
"a5a665ff33ec",
imageHeader,
ctx.Image,
},
{types.Container{
Image: "a5a665ff33eced1e0803148700880edab4",
ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5",
},
false,
"a5a665ff33eced1e0803148700880edab4",
imageHeader,
ctx.Image,
},
{types.Container{Image: ""}, true, "<no image>", imageHeader, ctx.Image}, {types.Container{Image: ""}, true, "<no image>", imageHeader, ctx.Image},
{types.Container{Command: "sh -c 'ls -la'"}, true, `"sh -c 'ls -la'"`, commandHeader, ctx.Command}, {types.Container{Command: "sh -c 'ls -la'"}, true, `"sh -c 'ls -la'"`, commandHeader, ctx.Command},
{types.Container{Created: unix}, true, time.Unix(unix, 0).String(), createdAtHeader, ctx.CreatedAt}, {types.Container{Created: unix}, true, time.Unix(unix, 0).String(), createdAtHeader, ctx.CreatedAt},

View file

@ -127,6 +127,7 @@ type Container struct {
ID string `json:"Id"` ID string `json:"Id"`
Names []string Names []string
Image string Image string
ImageID string
Command string Command string
Created int64 Created int64
Ports []Port Ports []Port

View file

@ -290,6 +290,7 @@ func (daemon *Daemon) transformContainer(container *Container, ctx *listContext)
newC := &types.Container{ newC := &types.Container{
ID: container.ID, ID: container.ID,
Names: ctx.names[container.ID], Names: ctx.names[container.ID],
ImageID: container.ImageID,
} }
img, err := daemon.Repositories().LookupImage(container.Config.Image) img, err := daemon.Repositories().LookupImage(container.Config.Image)

View file

@ -89,6 +89,7 @@ list of DNS options to be used in the container.
* `POST /build` now optionally takes a serialized map of build-time variables. * `POST /build` now optionally takes a serialized map of build-time variables.
* `GET /events` now includes a `timenano` field, in addition to the existing `time` field. * `GET /events` now includes a `timenano` field, in addition to the existing `time` field.
* `GET /info` now lists engine version information. * `GET /info` now lists engine version information.
* `GET /containers/json` will return `ImageID` of the image used by container.
### v1.20 API changes ### v1.20 API changes

View file

@ -47,6 +47,7 @@ List containers
"Id": "8dfafdbc3a40", "Id": "8dfafdbc3a40",
"Names":["/boring_feynman"], "Names":["/boring_feynman"],
"Image": "ubuntu:latest", "Image": "ubuntu:latest",
"ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82",
"Command": "echo 1", "Command": "echo 1",
"Created": 1367854155, "Created": 1367854155,
"Status": "Exit 0", "Status": "Exit 0",
@ -63,6 +64,7 @@ List containers
"Id": "9cd87474be90", "Id": "9cd87474be90",
"Names":["/coolName"], "Names":["/coolName"],
"Image": "ubuntu:latest", "Image": "ubuntu:latest",
"ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82",
"Command": "echo 222222", "Command": "echo 222222",
"Created": 1367854155, "Created": 1367854155,
"Status": "Exit 0", "Status": "Exit 0",
@ -75,6 +77,7 @@ List containers
"Id": "3176a2479c92", "Id": "3176a2479c92",
"Names":["/sleepy_dog"], "Names":["/sleepy_dog"],
"Image": "ubuntu:latest", "Image": "ubuntu:latest",
"ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82",
"Command": "echo 3333333333333333", "Command": "echo 3333333333333333",
"Created": 1367854154, "Created": 1367854154,
"Status": "Exit 0", "Status": "Exit 0",
@ -87,6 +90,7 @@ List containers
"Id": "4cb07b47f9fb", "Id": "4cb07b47f9fb",
"Names":["/running_cat"], "Names":["/running_cat"],
"Image": "ubuntu:latest", "Image": "ubuntu:latest",
"ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82",
"Command": "echo 444444444444444444444444444444444", "Command": "echo 444444444444444444444444444444444",
"Created": 1367854152, "Created": 1367854152,
"Status": "Exit 0", "Status": "Exit 0",