Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker inspect format returns different date format than inspect #14164

Closed
DavidJFelix opened this issue Jun 24, 2015 · 7 comments
Closed

Docker inspect format returns different date format than inspect #14164

DavidJFelix opened this issue Jun 24, 2015 · 7 comments

Comments

@DavidJFelix
Copy link

Relevant issues/pull requests:

#11706
#7670

Summary:

The docker inspect command issued with a -f formatting flag will cause times to be displayed in a manner that is inconsistent with the rest of the API.

Expected

Dates returned by docker inspect match dates returned by docker inspect -f identically, including formatting.

Observed

Dates do not match in formatting. One features a non-standard format.

Reproduce by:

  1. Issue a docker inspect command on a container
  2. Notice that times are delivered in ISO8601
  3. Issue a docker inspect -f {.State} to format the output and display an object that has a time in it.
  4. Notice that the times are delivered in a NON ISO8601 manner

Environment

  • docker version:
Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.1
Git commit (client): a8a31ef
OS/Arch (client): linux/amd64
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.4.1
Git commit (server): a8a31ef
  • docker info:
Containers: 26
Images: 82
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 134
Execution Driver: native-0.2
Kernel Version: 3.13.0-52-generic
Operating System: Ubuntu 14.04.2 LTS
CPUs: 2
Total Memory: 3.861 GiB
Name: vagrant
ID: N74I:YFQO:4DEY:I2EY:ZWBB:ZB45:UGHD:77SF:NXGS:BFUV:4QUN:B4SN
WARNING: No swap limit support
  • uname -a
Linux vagrant 3.13.0-52-generic #86-Ubuntu SMP Mon May 4 04:32:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
@erikthered
Copy link

Using docker inspect with no flags yields the following State block:

    "State": {
        "Running": false,
        "Paused": false,
        "Restarting": false,
        "OOMKilled": false,
        "Dead": false,
        "Pid": 0,
        "ExitCode": 137,
        "Error": "",
        "StartedAt": "2015-06-24T19:01:32.816007457Z",
        "FinishedAt": "2015-06-24T19:02:37.026871139Z"
    },

Whereas, docker inspect -f '{{.State.FinishedAt}}' yields:

2015-06-24 19:02:37.026871139 +0000 UTC

Filtering on just .State has the same issue:

{false false false false false 0 137  2015-06-24 19:01:32.816007457 +0000 UTC 2015-06-24 19:02:37.026871139 +0000 UTC}

docker version
Client version: 1.7.0
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 0baf609
OS/Arch (client): linux/amd64
Server version: 1.7.0
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 0baf609
OS/Arch (server): linux/amd64

docker info
Containers: 2
Images: 32
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 36
Dirperm1 Supported: true
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.19.0-21-generic
Operating System: Ubuntu 15.04
CPUs: 2
Total Memory: 3.86 GiB
Name: vulcan
ID: UASH:ETSF:KX4E:6YP7:HKBV:7BTN:QFEQ:XNEK:ZIH5:XPQV:YGQH:RPIM
WARNING: No swap limit support

uname -a
Linux vulcan 3.19.0-21-generic #21-Ubuntu SMP Sun Jun 14 18:31:11 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

@runcom
Copy link
Member

runcom commented Jun 30, 2015

This is because of the way the template is rendered with plain go objects.
docker inspect is working fine because it will defaults to json while -f {{.State}} isn't. This can also be checked doing -f {{json .State}} and times are rendered correctly (in the json format) I'll create a PR to fix this maybe

@runcom
Copy link
Member

runcom commented Jul 23, 2015

as per my previous comment I think this issue should be closed but feel free to ping me if I'm mistaken and I'll reopen it

@runcom runcom closed this as completed Jul 23, 2015
@MetalArend
Copy link

This bug is still present in Docker 18.03, both in docker inspect as in docker service inspect. Should I open a new report, or can we reopen this one?

@thaJeztah
Copy link
Member

Trying on Docker 18.06.1;

Default output;

docker inspect mycontainer

...
"State": {
    "Status": "running",
    "Running": true,
    "Paused": false,
    "Restarting": false,
    "OOMKilled": false,
    "Dead": false,
    "Pid": 14969,
    "ExitCode": 0,
    "Error": "",
    "StartedAt": "2018-09-17T11:35:38.801585592Z",
    "FinishedAt": "0001-01-01T00:00:00Z"
},
...

String presentation

docker inspect -f '{{.State}}' mycontainer
{running true false false false false 14969 0  2018-09-17T11:35:38.801585592Z 0001-01-01T00:00:00Z <nil>}

String presentation (only StartedAt);

docker inspect -f '{{.State.StartedAt}}' mycontainer
2018-09-17T11:35:38.801585592Z

JSON presentation

docker inspect -f '{{json .State}}' mycontainer
{"Status":"running","Running":true,"Paused":false,"Restarting":false,"OOMKilled":false,"Dead":false,"Pid":14969,"ExitCode":0,"Error":"","StartedAt":"2018-09-17T11:35:38.801585592Z","FinishedAt":"0001-01-01T00:00:00Z"}

@nospam2000
Copy link

In Docker version 19.03.4, build 9013bf583a there are still some inconsistencies when the timestamp is not stored with UTC ("Z") timezone , but with the explicit "json" prefix this can be solved:

$ docker image inspect -f '{{.Metadata.LastTagTime}}' 91858d4f2d4c
2020-02-20 20:14:14.766460032 +0100 CET

$ docker image inspect -f '{{json .Metadata.LastTagTime}}' 91858d4f2d4c
"2020-02-20T20:14:14.766460032+01:00"

For ".Created" which is stored with "Z" timezone there is no difference besides the quotes:
$ docker image inspect -f '{{json .Created}}' 91858d4f2d4c
"2020-02-20T16:59:24.777091227Z"

$ docker image inspect -f '{{.Created}}' 91858d4f2d4c
2020-02-20T16:59:24.777091227Z

@DavidJFelix
Copy link
Author

Honestly, I'd open a new issue for this. This issue is almost 5 years old and has been closed nearly since it opened. The consensus for the initial issue seemed to be use json but what you describe seems to be a different issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants