How do I get the exact exit time (Status field) in Docker ?
I can only get "Exited (0) 3 days ago"
I know I can get the exact creation time with this command:
docker ps --format 'table {{.ID}}\t{{.Command}}\t{{.CreatedAt}}'
But if I change it to:
docker ps --format 'table {{.ID}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
the status is not in exact format it’s shows "Exited (0) 3 days ago" again.
Is there any field with the exact time ? I also couldn’t find a reference table to all fields. Where is it ?
>Solution :
The "Status" field in the output of ‘docker ps’ command shows the current status of the container, which includes the exit code and the time elapsed since the container exited. As you have noticed, it only shows a relative time ("3 days ago") and not the exact time.
To get the exact exit time of a container, you can use the docker inspect command with the ‘–format’ option. Here’s an example:
docker inspect --format='{{.State.FinishedAt}}' <container_id>
This will output the exact time when the container finished, in UTC format (e.g. "2022-03-09T18:25:30.86454711Z"). You can adjust the output format using Go’s time formatting syntax, for example:
docker inspect --format='{{.State.FinishedAt.Format "2006-01-02 15:04:05"}}' <container_id>
This will output the same timestamp in the format "YYYY-MM-DD HH:mm:ss" (e.g. "2022-03-09 18:25:30").
Regarding your question about a reference table to all fields, you can find the complete list of fields that can be used with the ‘–format’ option in the official Docker documentation: https://docs.docker.com/config/formatting/.